0

我在使用 MVCContrib Fluent 路由测试来测试路由时遇到问题。测试失败,但应用程序识别路由。

让我解释....

我的寄存器中有以下路线(按顺序显示)

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" }
            );

路由管道正确地将请求发送到路由 1的Index和路由 2 的Show

但是,当我使用 MVCContrib 流利的类测试路由时,路由 1 的测试失败。

测试是:

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

测试失败,因为期望是Index但实际是Show

关于为什么流利的类没有识别正确的路由但 mvc 路由在实际应用程序中起作用的任何想法?或者没有关于如何调整我的测试或路线以允许我进行全面测试的任何建议?

4

1 回答 1

2

你的测试应该是:

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

网址是~/PurchaseUnits/Page1而不是~/PurchaseUnits/Page{page}

于 2010-10-21T11:22:13.600 回答