加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

单元测试 – MVCContrib测试路径与区域

发布时间:2020-12-16 06:43:04 所属栏目:asp.Net 来源:网络整理
导读:我正在使用带有区域的MVC 2.为了测试路由,我使用的是MvcContrib. 这是测试代码: [Test]public void Home(){ MvcApplication.RegisterRoutes(RouteTable.Routes); "~/".ShouldMapToHomeController(x = x.Login("Nps"));} 我不知道如何调用存储在Regions中的
我正在使用带有区域的MVC 2.为了测试路由,我使用的是MvcContrib.

这是测试代码:

[Test]
public void Home()
{
    MvcApplication.RegisterRoutes(RouteTable.Routes);
    "~/".ShouldMapTo<HomeController>(x => x.Login("Nps"));
}

我不知道如何调用存储在Regions中的路由定义.
调用AreaRegistration.RegisterAllAreas()不是一个选项,因为它给出了一个例外.

谢谢
勒万

解决方法

这就是我这样做的方式,对我有用

[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());
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读