단위 테스트에서 컨트롤러 작업이 실제로 특정 페이지로 리디렉션되는지 확인하는 간단한 방법이 있습니까?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