public void MapMvcAttributeRoutes_WithPrefixedController() { // Arrange var controllerTypes = new[] { typeof(PrefixedController) }; var routes = new RouteCollection(); // Act routes.MapMvcAttributeRoutes(controllerTypes); // Assert Assert.Equal(1, routes.Count); Route route = (Route)routes.Single(); Assert.Equal("prefpref/getme", route.Url); Assert.Equal("GetMe", route.GetTargetActionMethod().Name); }
public void MapMvcAttributeRoutes_MapRouteAttributes() { // Arrange var controllerTypes = new[] { typeof(SimpleRoutingController) }; var routes = new RouteCollection(); // Act routes.MapMvcAttributeRoutes(controllerTypes); // Assert var expectedResults = new List <Tuple <string, string, string[]> > { new Tuple <string, string, string[]>("getme", "GetMe", new[] { "GET" }), new Tuple <string, string, string[]>("postme", "PostMe", new[] { "POST" }), new Tuple <string, string, string[]>("getorpostme", "GetOrPostMe", new[] { "GET", "POST" }), new Tuple <string, string, string[]>("routeme", "RouteMe", null), new Tuple <string, string, string[]>("once", "FoolMe", new[] { "GET" }), new Tuple <string, string, string[]>("twice", "FoolMe", new[] { "GET" }), new Tuple <string, string, string[]>("twice", "FoolMe", new[] { "GET" }), }; foreach (var expected in expectedResults) { var url = expected.Item1; var methodName = expected.Item2; var expectedHttpMethods = expected.Item3; Route route = routes.Cast <Route>().Single(r => r.Url == url); Assert.Equal(methodName, route.GetTargetActionMethod().Name); var httpMethodConstraint = (HttpMethodConstraint)route.Constraints["httpMethod"]; if (expectedHttpMethods == null) { Assert.Null(httpMethodConstraint); } else { Assert.NotNull(httpMethodConstraint); var actualHttpMethods = httpMethodConstraint.AllowedMethods.ToArray(); Array.Sort(expectedHttpMethods); Array.Sort(actualHttpMethods); Assert.Equal(expectedHttpMethods, actualHttpMethods); } } }
public void MapMvcAttributeRoutes_WithPrefixedArea() { // Arrange var controllerTypes = new[] { typeof(PrefixedPugetSoundController) }; var routes = new RouteCollection(); // Act routes.MapMvcAttributeRoutes(controllerTypes); // Assert Assert.Equal(1, routes.Count); Route route = (Route)routes.Single(); Assert.Equal("puget-sound/prefpref/getme", route.Url); Assert.Equal("PugetSound", route.DataTokens["area"]); Assert.Equal(false, route.DataTokens["usenamespacefallback"]); Assert.Equal("GetMe", route.GetTargetActionMethod().Name); Assert.Equal(typeof(PrefixedPugetSoundController).Namespace, ((string[])route.DataTokens["namespaces"])[0]); }