我正在使用带有区域的 MVC 2。为了测试路由,我使用 MvcContrib。
这是测试代码:
[Test]
public void Home()
{
MvcApplication.RegisterRoutes(RouteTable.Routes);
"~/".ShouldMapTo<HomeController>(x => x.Login("Nps"));
}
我不确定如何调用存储在区域中的路由定义。
调用 AreaRegistration.RegisterAllAreas() 不是一个选项,因为它给出了一个异常(exception)。
谢谢
雷文
最佳答案
这是我这样做的方式,它对我有用
[Test]
public void VerifyRouteMapFor_Test_Area_TestController()
{
RouteTable.Routes.Clear();
var testAreaRegistration = new testAreaRegistration();
testAreaRegistration.RegisterArea(new AreaRegistrationContext(testAreaRegistration.AreaName, RouteTable.Routes));
"~/test/index".ShouldMapTo<testController>(x => x.Index());
}
关于unit-testing - MVCContrib 带区域的测试路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2672087/