开发者

Issue with mvcContrib fluent route testing in asp.net mvc

开发者 https://www.devze.com 2023-01-20 13:51 出处:网络
I have an issue with testing routes using the MVCContrib Fluent route testing. The test fails yet the application recognises the routes.

I have an issue with testing routes using the MVCContrib Fluent route testing. 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", act开发者_JAVA百科ion = "Show" }
            );

The routing pipeline correctly sends requests to Index for route 1 and Show for route 2.

However when I test the routing using the MVCContrib fluent classes I get a test fail for route 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.

Any ideas as to why the fluent classes aren't identifying the correct routing yet the mvc routing works in the actual application? 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}.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号