Unit Testing Monorail's RedirectToReferrer()
-
09-06-2019 - |
Question
I am trying to write a unit test for an action method which calls the Controller.RedirectToReferrer()
method, but am getting a "No referrer available" message.
How can I isolate and mock this method?
Solution
Have you thought about creating a test double?
OTHER TIPS
In my version of the trunk I'm working against, r5299, I had to do this to mock out RedirectToReferrer. I think it's been changed in recent commits, I'm not sure.
[TestFixture]
public class LoginControllerTests : GenericBaseControllerTest<LoginController>
{
private string referrer = "http://www.example.org";
protected override IMockRequest BuildRequest()
{
var request = new StubRequest(Cookies);
request.UrlReferrer = referrer;
return request;
}
protected override IMockResponse BuildResponse(UrlInfo info)
{
var response = new StubResponse(info,
new DefaultUrlBuilder(),
new StubServerUtility(),
new RouteMatch(),
referrer);
return response;
}
etc. etc.
It's oddly the Response that you need to molest to get the RedirectToReferrer
to work. I had to crawl around in the monorail sources to figure it out.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow