AnthonySteele / MvcRouteTester

A library for unit testing ASP MVC route tables for both Web and API Routes
Apache License 2.0
105 stars 43 forks source link

How to setup attribute routing #45

Closed bapti closed 9 years ago

bapti commented 10 years ago

I have the following code for setting up my MVC routes

public static void RegisterAllRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    routes.MapMvcAttributeRoutes();
    RegisterAreas(routes);
    RegisterConventionRoutes(routes);
}

I see from your code that you've got routes.MapAttributeRoutesInAssembly(typeof(HomeAttrController)); for setting up the routing for testing.

Should I be doing something like this?

public static void RegisterAllRoutes(RouteCollection routes, Action registerAttributesAction)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    registerAttributesAction.Invoke();
}

// Prod code
RegisterAllRoutes(routes, () => { routes.MapMvcAttributeRoutes();});

// Test code
RegisterAllRoutes(routes, () => { routes.MapAttributeRoutesInAssembly();});

Would this be the best pattern for testing do you think?