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}
.
精彩评论