我正在测试控制器是否没有参数,它应该重定向到操作"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?
答案 0 :(得分:2)
你需要像这样查看RouteValues字典:
Assert.AreEqual("Index", (result as RedirectToRouteResult).RouteValues["action"]);