简体   繁体   English

在ASP.NET MVC中使用MVC进行流利的路由测试的问题

[英]Issue with mvcContrib fluent route testing in asp.net mvc

I have an issue with testing routes using the MVCContrib Fluent route testing. 我在使用MVCContrib Fluent路由测试来测试路由时遇到问题。 The test fails yet the application recognises the routes. 测试失败,但应用程序识别出路由。

Let me explain.... 让我解释....

I have the following routes in my register (shown in order) 我的寄存器中有以下路线(按顺序显示)

routes.MapRoute(
                "PurchaseUnitsPaged",
                "PurchaseUnits/Page{page}",
                new { controller = "PurchaseUnits", action = "Index", page = 1 },
                new { page = @"\d+" }
                );


routes.MapRoute(
                "PurchaseUnit",
                "PurchaseUnits/{unitname}",
                new { controller = "PurchaseUnits", action = "Show" }
            );

The routing pipeline correctly sends requests to Index for route 1 and Show for route 2. 路由管道正确地将请求发送到索引显示路由1,并显示请求以显示路由2。

However when I test the routing using the MVCContrib fluent classes I get a test fail for route 1. 但是,当我使用MVCContrib流利的类测试路由时,路由1的测试失败。

The test is: 测试是:

"~/PurchaseUnits/Page{page}".ShouldMapTo<PurchaseUnitsController>(x=> x.Index(1));

The test fails because the expectation is Index but the actual is Show . 测试失败,因为期望值是Index而实际值是Show

Any ideas as to why the fluent classes aren't identifying the correct routing yet the mvc routing works in the actual application? 关于为什么流利的类不能识别正确的路由,但mvc路由在实际应用程序中起作用的任何想法? Or failing that any suggestions about how I can tweak my test or routes to allow me to fully test? 还是没有任何有关如何调整测试或路线以使我能够进行全面测试的建议?

Your test should be: 您的测试应为:

"~/PurchaseUnits/Page1".ShouldMapTo<PurchaseUnitsController>(x=> x.Index(1));

The url is ~/PurchaseUnits/Page1 and not ~/PurchaseUnits/Page{page} . 网址是~/PurchaseUnits/Page1而不是~/PurchaseUnits/Page{page}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM