Frage

Wie führe ich eine Aktion aus, um sicherzustellen, dass sie zur richtigen Aktion oder Route umgeleitet wird?

War es hilfreich?

Lösung

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

}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top