use*_*993 4 unit-testing asp.net-mvc-routing mvccontrib
我正在使用带有区域的MVC 2.为了测试路由,我使用的是MvcContrib.
这是测试代码:
[Test]
public void Home()
{
MvcApplication.RegisterRoutes(RouteTable.Routes);
"~/".ShouldMapTo<HomeController>(x => x.Login("Nps"));
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何调用存储在Regions中的路由定义.调用AreaRegistration.RegisterAllAreas()不是一个选项,因为它给出了一个例外.
谢谢Revin
这就是我这样做的方式,对我有用
[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());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1268 次 |
| 最近记录: |