unit-testing - MVCContrib 带区域的测试路线

标签 unit-testing asp.net-mvc-routing mvccontrib

我正在使用带有区域的 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/

相关文章:

asp.net-mvc - ASP.NET MVC - 以 HTML 或 XML 形式返回数据

java - 使用 maven 运行单个测试方法

reactjs - 使用 React 测试库指南进行单元测试 Redux 工具包

用于编译测试的 CMake 和 CMocka 标准断言

unit-testing - TDD:您为单元测试公开了哪些方法?

asp.net-mvc - 如何在 ASP.NET MVC 路由中使用带有 HttpMethodConstraint 的自定义约束?

asp.net-mvc - 带参数的 MvcContrib Windsor 设置组件

c# - 当 URL 中有尾随空格时 WebAPI 路由 404

c# - 将参数传递给 Controller ​​ ..但不在 URL 上

c# - MVC Contrib VerificationException