How test that ASP.NET MVC route redirects to other site?

Posted by Matt Lacey on Stack Overflow See other posts from Stack Overflow or by Matt Lacey
Published on 2010-03-16T10:41:15Z Indexed on 2010/03/17 10:41 UTC
Read the original article Hit count: 375

Due to a prinitng error in some promotional material I have a site that is receiving a lot of requests which should be for one site arriving at another.
i.e.
The valid sites are http://site1.com/abc & http://site2.com/def but people are being told to go to http://site1.com/def.

I have control over site1 but not site2.

site1 contains logic for checking that the first part of the route is valid in an actionfilter, like this:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    base.OnActionExecuting(filterContext);

    if ((!filterContext.ActionParameters.ContainsKey("id")) 
     || (!manager.WhiteLabelExists(filterContext.ActionParameters["id"].ToString())))
    {
        if (filterContext.ActionParameters["id"].ToString().ToLowerInvariant().Equals("def"))
        {
            filterContext.HttpContext.Response.Redirect("http://site2.com/def", true);
        }

        filterContext.Result = new ViewResult { ViewName = "NoWhiteLabel" };
        filterContext.HttpContext.Response.Clear();
    }
}

I'm not sure how to test the redirection to the other site though.
I already have tests for redirecting to "NoWhiteLabel" using the MvcContrib Test Helpers, but these aren't able to handle (as far as I can see) this situation.

How do I test the redirection to antoher site?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about unit-testing