Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP .NET Web API controller testing

I'd like to unit test some controller actions and ultimately test that validation attributes and action response filters are functioning properly. To do this sort of thing in ASP .NET MVC was easy with mvccontrib; however, with Web API, mocking the HttpContext seems to be quite a bit different.

How do I go about mocking HttpContext for a Web API controller so that I can test model binding and the like?

like image 777
bradjive Avatar asked Nov 03 '22 22:11

bradjive


1 Answers

You shouldn't need HttpContext in a Web API. Everything you need should be in the HttpRequestMessage and its Properties collection.

like image 191
Darrel Miller Avatar answered Nov 11 '22 15:11

Darrel Miller