且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何做单元测试的IgnoreRoute在ASP.NET MVC

更新时间:2023-02-17 12:37:07

我要检查RouteHandler上的RouteData匹配的忽略路径的路由型StopRoutingHandler的;

I would check that the RouteHandler on the RouteData for a route matching the ignored path is of type 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) );
    }