如何做单元测试的IgnoreRoute在ASP.NET MVC [英] How do unit testing for IgnoreRoute in ASP.NET MVC
问题描述
在ASP.NET MVC中,我可以对路线和定制路由单元测试的信息,但我无法弄清楚如何为IgnoreRoute做单元测试。
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({}资源个.axd / {*} PATHINFO);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
实用code是多少AP preciated。
Practical code is much appreciated.
<一个href=\"http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx\">ASP.NET MVC框架(第二部分):URL路由
<一个href=\"http://stephenwalther.com/blog/archive/2008/07/02/asp-net-mvc-tip-13-unit-test-your-custom-routes.aspx\">ASP.NET MVC提示#13 - 单元测试您的自定义路线
<一个href=\"http://stephenwalther.com/blog/archive/2008/08/07/asp-net-mvc-tip-30-create-custom-route-constraints.aspx\">ASP.NET MVC提示#30 -
推荐答案
我要检查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) );
}
这篇关于如何做单元测试的IgnoreRoute在ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!