ASP MVC 5测试RedirectToAction

时间:2015-02-06 16:06:20

标签: asp.net asp.net-mvc unit-testing tdd

我正在测试控制器是否没有参数,它应该重定向到操作"Index"

// Controller code
return RedirectToAction("Index");

// Unit test code
ActionResult result = Controller.Action(null);
Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
Assert. // HERE i need to test it is going to Index, how do I do that?

1 个答案:

答案 0 :(得分:2)

你需要像这样查看RouteValues字典:

Assert.AreEqual("Index", (result as RedirectToRouteResult).RouteValues["action"]);