MVCContrib 测试路线与区域
我正在将 MVC 2 与区域一起使用。为了测试路由,我使用 MvcContrib。
这是测试代码:
[Test]
public void Home()
{
MvcApplication.RegisterRoutes(RouteTable.Routes);
"~/".ShouldMapTo<HomeController>(x => x.Login("Nps"));
}
我不确定如何调用存储在区域中的路由定义。 调用 AreaRegistration.RegisterAllAreas() 不是一个选项,因为它会给出异常。
谢谢 雷文
I am using MVC 2 with Areas. To test routing, I am using MvcContrib.
This is the testing code:
[Test]
public void Home()
{
MvcApplication.RegisterRoutes(RouteTable.Routes);
"~/".ShouldMapTo<HomeController>(x => x.Login("Nps"));
}
I am not sure how to call routing definition that are stored in Areas.
Calling AreaRegistration.RegisterAllAreas() is not an option as it gives an exception.
Thanks
Revin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我做事的方式,对我有用
This is the way I do it which works for me
您应该为您正在测试的区域调用 AreaRegistration,而不是调用 RegisterAllAreas。 RegisterAllAreas 扫描所有已加载的程序集,因此对于测试而言执行的操作过多。我会手动设置测试。如果仍然通过并且出现异常,请将其发布到此处或 mvccontrib 邮件列表。我确信在某些情况下 TestHelper 需要更新以更好地支持领域。我们还没有为测试助手添加任何特定区域的支持。
Rather than calling RegisterAllAreas, you should call the AreaRegistration for that area you are testing. The RegisterAllAreas scans all the loaded assemblies and as a result does too much for a test. I would manually setup the test. If it still throughs and exception post it here or to the mvccontrib mailing list. I am sure that there are some cases where the TestHelper needs to be updated to support areas better. We have not added any specific area support to the test helpers yet.
对于单元测试,也许最好只进行一个区域。但对于集成测试,您需要测试上下文中的所有路由,我认为。
For a unit test, perhaps it's best to just do the one area. But for an integration test, you'd want to test all the routes in the context, imo.