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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top