Skip to content

A library for unit testing ASP.Net routing tables for WebForms

License

Notifications You must be signed in to change notification settings

ogaudefroy/WebFormsRouteUnitTester

Repository files navigation

WebFormsRouteUnitTester

A library for unit testing ASP.Net routing tables for WebForms. Supports inbound and outbound route testing

Build status NuGet version

Initialize RouteTester

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

Inbound route testing

  • 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();

Outbound route testing

  • 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

About

A library for unit testing ASP.Net routing tables for WebForms

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages