Exemple #1
0
        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]);
        }
Exemple #2
0
        public void AttributeRouting_AmbiguousActions_ThrowsAmbiguousException(Type controllerType, string path)
        {
            // Arrange
            var controllerTypes = new[] { controllerType };
            var routes          = new RouteCollection();

            routes.MapMvcAttributeRoutes(controllerTypes);

            HttpContextBase context        = GetContext(path);
            RouteData       routeData      = routes.GetRouteData(context);
            RequestContext  requestContext = new RequestContext(context, routeData);
            MvcHandler      handler        = new MvcHandler(requestContext);

            handler.ControllerBuilder.SetControllerFactory(GetControllerFactory(controllerTypes));

            // Act
            // Bug 1285: Attribute routing with ambiguous actions should throw an AmbiguousMatchException.
            // This test should fail once that is fixed. Uncomment the line below then.
            // Assert.Throws<AmbiguousMatchException>(() => handler.ProcessRequest(context));
            Assert.DoesNotThrow(() => handler.ProcessRequest(context));
        }
        public void MapMvcAttributeRoutes_WithArea()
        {
            // Arrange
            var controllerTypes = new[] { typeof(PugetSoundController) };
            var routes          = new RouteCollection();

            // Act
            routes.MapMvcAttributeRoutes(controllerTypes);


            // Assert
            var attributeRoutes = GetAttributeRoutes(routes);

            Assert.Equal(1, attributeRoutes.Count);

            Route route = (Route)attributeRoutes.Single();

            Assert.Equal("puget-sound/getme", route.Url);
            Assert.Equal("PugetSound", route.DataTokens["area"]);
            Assert.Equal(false, route.DataTokens["usenamespacefallback"]);
            Assert.Equal("GetMe", Assert.Single(route.GetTargetActionDescriptors()).ActionName);
            Assert.Equal(typeof(PugetSoundController).Namespace, ((string[])route.DataTokens["namespaces"])[0]);
        }
Exemple #4
0
        public void AttributeRouting_WithInheritance_MethodOverrides(Type derivedController, string path, string expectedAction)
        {
            // Arrange
            var controllerTypes = new[] { derivedController, derivedController.BaseType };
            var routes          = new RouteCollection();

            routes.MapMvcAttributeRoutes(controllerTypes);

            HttpContextBase context        = GetContext(path);
            RouteData       routeData      = routes.GetRouteData(context);
            RequestContext  requestContext = new RequestContext(context, routeData);
            MvcHandler      handler        = new MvcHandler(requestContext);

            handler.ControllerBuilder.SetControllerFactory(GetControllerFactory(controllerTypes));

            // Act
            handler.ProcessRequest(context);

            // Assert
            ContentResult result = Assert.IsType <ContentResult>(context.Items[ResultKey]);

            Assert.Equal(expectedAction, result.Content);
        }