【发布时间】:2012-06-01 07:55:58
【问题描述】:
我有这个控制器方法:
[GET("/whatever/list")]
public ActionResult Index(string sortby, string order)
我正在尝试使用 MvcContrib 路由测试对其进行测试:
"~/whatever/list".ShouldMapTo<MyController>(c => c.Index(string.Empty, string.Empty));
"~/whatever/list?sortby=type&order=desc".ShouldMapTo<MyController>(c => c.Index("type", "desc"));
但是,它返回此错误。
失败:MvcContrib.TestHelper.AssertionException:值为 参数“sortby”不匹配:预期为“”但为“”;没有价值 在名为“sortby”的路由上下文操作参数中找到 - 你的 匹配的路由包含一个名为“sortby”的标记?
我错过了什么?
【问题讨论】:
-
我认为第一个测试失败::
"~/whatever/list".ShouldMapTo<MyController>(c => c.Index(string.Empty, string.Empty));尝试使用null而不是string.Empty,因为null是string的默认值。 -
如果您将其作为答案,我会将其标记为已回答。这似乎做到了,我不知道为什么没有打到我。
标签: asp.net-mvc mvccontrib attributerouting