【发布时间】:2010-11-11 17:17:12
【问题描述】:
我正在尝试使用 MvcContrib TestHelper 流畅的路由测试 API,但我看到了奇怪的行为。 .WithMethod(HttpVerb) 扩展方法似乎没有按预期执行。这是我的控制器,显示了 (2) 个接受不同 HttpVerbs 的操作(名称相同):
[HttpGet]
public ActionResult IdentifyUser()
{
return View(new IdentifyUserViewModel());
}
[HttpPost]
public ActionResult IdentifyUser(IdentifyUserInputModel model)
{
return null;
}
下面是应该映射到具有 [HttpPost] 属性的操作的测试:
MvcApplication.RegisterRoutes(RouteTable.Routes);
var routeData = "~/public/registration/useridentification/identifyuser"
.WithMethod(HttpVerbs.Post)
.ShouldMapTo<UserIdentificationController>(x => x.IdentifyUser(null));
即使在我的测试中指定了 POST HttpVerb,它也总是路由到 HttpGet 方法。 我什至可以在我的控制器中注释掉接受 HttpPost 的动作并且仍然通过测试!
这里有什么我遗漏的吗?
【问题讨论】:
标签: asp.net-mvc-2 nunit mvccontrib-testhelper