문제

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