A library for unit testing ASP.Net routing tables for WebForms. Supports inbound and outbound route testing
var routes = new RouteCollection();
routes.Ignore("content/{*content}");
routes.MapPageRoute("Cookies", "cookies", "~/pages/cookies.aspx");
routes.MapPageRoute(
routeName: "ItemDetails",
routeUrl: "{culture}/items/{id}",
physicalFile: "~/pages/items/details.aspx",
checkPhysicalUrlAccess: false,
defaults: new RouteValueDictionary(new { culture = "en-US" }));
var tester = new RouteTester(routes);
- Without parameters
tester.WithIncomingRequest("/cookies")
.ShouldMatchPageRoute("~/Pages/General/Cookies.aspx");
- With parameters
tester.WithIncomingRequest("en-US/items/33")
.ShouldMatchPageRoute("~/pages/items/details.aspx", new { culture = "en-US", id = 33 });
- Ignored routes
tester.WithIncomingRequest("content/bg666")
.ShouldBeIgnored();
- Missing routes
tester.WithIncomingRequest("fake")
.ShouldMatchNoRoute();
- Without parameters
tester.WithRouteInfo("Cookies")
.ShouldGenerateUrl("/cookies");
- With parameters
tester.WithRouteInfo("ItemDetails", new { id = 13, culture = "fr-FR"})
.ShouldGenerateUrl("/fr-FR/items/13");
- Parameter default values testing
tester.WithRouteInfo("ItemDetails", new { id = 13})
.ShouldGenerateUrl("/en-US/items/13");
Inspired by MvcRouteUnitTester