Last post Apr 27, 2010 08:09 AM by mvcnoob1
Apr 27, 2010 04:40 AM|mvcnoob1|LINK
Hello MVC gurus!
How can I unit test an action which alters the Http Response object? I haven't been able to solve this. I can mock the object but can't see how I can check the value after the action runs. I set the Response.StatusCode when errors occur in ajax requests
and need to check it has been set in the unit test. The only alternative I can see is to change all my actions to return json objects with a IsSuccessful flag or similar. I appreciate your help.
MVC Noob #1
"Programming ASP.NET MVC"
Apr 27, 2010 06:46 AM|andrewm66|LINK
Have you tried using Fiddler?
You can use it to view HTTP traffic, including Request & responses
Apr 27, 2010 07:03 AM|mvcnoob1|LINK
I am looking for a unit test solution that can be automated
Apr 27, 2010 07:33 AM|ignatandrei|LINK
Apr 27, 2010 07:49 AM|Augi|LINK
Actually, you should never alter HttpResponse object in your controller/action. All work on HttpResponse should be done in action result, in
When you are testing, then you only have to check that the right action result has been returned. You don't have to execute this result.
You could want to test action result class - you can and then you should use some mocking framework, as suggested in linked article above...
Apr 27, 2010 08:09 AM|mvcnoob1|LINK
The following post in stackoverflow recommended setting the Response status code which is where I got the idea from:
So are you suggesting that I go with the json view model solution instead?