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

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top