dimanche 3 juillet 2016

HttpContext.Current is null when unit test

I have following web Api controller method.

When i run this code through web, HttpContext.Current is never null and give desired value.

public override void Post([FromBody]TestDTO model)
    {

        var request = HttpContext.Current.Request;
        var testName = request.Headers.GetValues("OS Type")[0];
        // more code

    }

However, when i call this method from Unit Test, HttpContext.Current is always null.

How do i fix it?

Aucun commentaire:

Enregistrer un commentaire