How do I exercise an action to ensure it redirects to the correct action or route?
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"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With