简体   繁体   中英

Issue with mvcContrib fluent route testing in asp.net mvc

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", action = "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} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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