Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assert action redirected to correct action/route?

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

like image 977
Dane O'Connor Avatar asked Aug 28 '08 14:08

Dane O'Connor


1 Answers

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"));

}
like image 83
Ben Scheirman Avatar answered Sep 20 '22 00:09

Ben Scheirman