如何在ASP.NET MVC中对IgnoreRoute进行单元测试

12 asp.net-mvc unit-testing routes

在ASP.NET MVC中,我可以获得有关路由和自定义路由的单元测试的信息,但我无法弄清楚如何对IgnoreRoute进行单元测试.

routes.IgnoreRoute( "{}资源个.axd/{*} PATHINFO");

实用的代码非常感谢.

ASP.NET MVC框架(第2部分):URL路由

ASP.NET MVC提示#13 - 单元测试您的自定义路由

ASP.NET MVC技巧#30 - 创建自定义路由约束

tva*_*son 15

我会检查RouteData上与被忽略路径匹配的路由的RouteHandler是否类型为StopRoutingHandler;

    [TestMethod]
    public void TestIgnoredRoute()
    {
        // Arrange
        var routes = new RouteCollection();
        GlobalApplication.RegisterRoutes(routes);

        // Act
        var context = new FakeHttpContext("~/some.axd/path");
        var routeData = routes.GetRouteData(context);

        // Assert
        Assert.IsInstanceOfType( routeData.RouteHandler, typeof(StopRoutingHandler) );
    }
Run Code Online (Sandbox Code Playgroud)