How do unit testing for IgnoreRoute in ASP.NET MVC

后端 未结 2 510
终归单人心
终归单人心 2021-02-14 00:22

In ASP.NET MVC, I can get information on unit testing for routes and custom routes, but I can not figure out how to do unit testing for IgnoreRoute.

routes.IgnoreRoute(\

2条回答
  •  生来不讨喜
    2021-02-14 00:51

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

提交回复
热议问题