0

How do I test if a URL returns http 404 error in ASP.NET MVC 3? I would like to write a small test to check if a view is being called when I write a specific URL.

Thanks.

giftcv
  • 1,670
  • 15
  • 23
abenci
  • 8,422
  • 19
  • 69
  • 134
  • 1
    Have a look at this question/reply http://stackoverflow.com/questions/619895/how-can-i-properly-handle-404-in-asp-net-mvc – Huske Nov 22 '11 at 08:57

1 Answers1

0

Mock the httpContextBase of your controller with mvcContrib-test helper and check what is the response status like that:

Response.StatusCode == 404;
gdoron
  • 147,333
  • 58
  • 291
  • 367
  • Thanks gdoron, any other chance without installing any helper on dev and build machines? – abenci Nov 23 '11 at 07:46
  • @devdept, Welll you don't have to install anything, but mocking httpContext is a terrible headache. BTW, it's just a package from nuget, why not install it and save time for coffee? – gdoron Nov 23 '11 at 08:37