我正在尝试使用MvcContrib TestHelper fluent路由测试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的动作,并且仍然可以通过测试!
这里有什么东西我遗漏了吗?
发布于 2010-11-11 22:39:09
这可能与你如何注册路线有关。我通常创建一个只做这个的类。因此,在进行上述测试之前,我要确保适当地设置测试夹具。
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
RouteTable.Routes.Clear();
new RouteConfigurator().RegisterRoutes(RouteTable.Routes);
}我的猜测是,由于RouteTable静态地处理它们,您可能会遇到问题,方法是不添加、不清除,或者在每次测试运行时添加太多的路由。
https://stackoverflow.com/questions/4157161
复制相似问题