views:

250

answers:

2

How do I exercise an action to ensure it redirects to the correct action or route?

+4  A: 
public ActionResult Foo()
{
   return RedirectToAction("Products", "Index");
}

[Test]
public void foo_redirects_to_products_index()
{
   var controller = new BarController();
   var result = controller.Foo() as RedirectToRouteResult;

   if(result == null)
      Assert.Fail("should have redirected");

   Assert.That(result.RouteData.Values["Controller"], Is.EqualTo("Products"));
   Assert.That(result.RouteData.Values["Action"], Is.EqualTo("Index"));

}
Ben Scheirman
A: 

Do not route truck on to eagle bend road in clinton tenn, this is a no trucks route. This is a narrow road that is not made for big riggs. A accident waiting to happen.

donnie rosenbalm