のユニットテストでリダイレクトを確認するコントローラのアクションが実際に特定のページにリダイレクトされていることを単体テストで簡単に確認する方法はありますか?asp.net mvc
コントローラーコード:
public ActionResult Create(ProductModel newProduct)
{
this.repository.CreateProduct(newProduct);
return RedirectToAction("Index");
}
だから私のテストでは、私は、コントローラが実際にリダイレクトされていることを確認する必要があります。
ProductController controller = new ProductController(repository);
RedirectToRouteResult result = (RedirectToRouteResult)controller.Create(newProduct);
bool redirected = checkGoesHere;
Assert.True(redirected, "Should have redirected to 'Index'");
確認の方法はわかりません。何か案は?
おかげでダーリンを...
希望をこのような何かを行うことができます。 –
+1 TestHelperへのリンク –
このMvcContribライブラリは素晴らしいです! – will