Hello,
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?
Thanks, -- rauchy
Hello,
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?
Thanks, -- rauchy
This question was answered on the castle forums: http://forum.castleproject.org/viewtopic.php?p=13743
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.
Cheers!