如何对MVC重定向进行单元测试?
public ActionResult Create(Product product)
{
_productTask.Save(product);
return RedirectToAction("Index",new {id = product.Id});
}
public ActionResult Index(int id)
{
return View();
}
这里我使用了单元测试语句
var result = controller.CreateGroup(group) as RedirectToRouteResult;
//// Assert
Assert.That(result, Is.Not.Null);
但它失败结果返回null值 任何人都可以帮助我
答案 0 :(得分:0)
// Arrange
var product = new Product(){Id=1};
// Act
var result = controller.Create(product);
// Assert
result.AssertActionRedirect()
.ToController("thisControllerName")
.ToAction("Index");