Created
December 29, 2016 21:20
-
-
Save miguelludert/6723d5139fb296843f6cefb9e6c9d8e0 to your computer and use it in GitHub Desktop.
Unit Testing Routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void MapMvcAttributeRoutes(this RouteCollection routeCollection, Assembly controllerAssembly) | |
{ | |
var controllerTypes = (from type in controllerAssembly.GetExportedTypes() | |
where | |
type != null && type.IsPublic | |
&& type.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase) | |
&& !type.IsAbstract && typeof(IController).IsAssignableFrom(type) | |
select type).ToList(); | |
var attributeRoutingAssembly = typeof(RouteCollectionAttributeRoutingExtensions).Assembly; | |
var attributeRoutingMapperType = | |
attributeRoutingAssembly.GetType("System.Web.Mvc.Routing.AttributeRoutingMapper"); | |
var mapAttributeRoutesMethod = attributeRoutingMapperType.GetMethod( | |
"MapAttributeRoutes", | |
BindingFlags.Public | BindingFlags.Static, | |
null, | |
new[] { typeof(RouteCollection), typeof(IEnumerable<Type>) }, | |
null); | |
mapAttributeRoutesMethod.Invoke(null, new object[] { routeCollection, controllerTypes }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment