Question

I need to test Response.Redirect, of course if i'm in a controller action i can use the RedirectResult or RedirectToActionResult, but what if i'm not in a controller action method but in the void Application_Error method in Global.asax ?

thanks

Était-ce utile?

La solution

You don't want to test Response.Redirect, you want to to test whether it is called or not, right? You can abstract this by creating an interface, say, IRedirector with a method Redirect, and use it in your Global.asax. Then, in your test you can use a mock, say RedirectorMock, which does nothing (as opposed to the real one, which redirects to the constructor-provided url), and see whether the RedirectorMock.Redirect has been called.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top