Esempio n. 1
0
        public void CreateRouteEntry_IfDirectRouteProviderReturnsRouteWithEmptyActionDescriptors_Throws()
        {
            // Arrange
            string areaPrefix       = null;
            string controllerPrefix = null;
            Route  route            = new Route(url: null, routeHandler: null);

            route.DataTokens = new RouteValueDictionary();
            route.DataTokens.Add(RouteDataTokenKeys.Actions, new ActionDescriptor[0]);
            ActionDescriptor[] originalActions = route.GetTargetActionDescriptors();
            Assert.NotNull(originalActions); // Guard
            Assert.Empty(originalActions);   // Guard
            RouteEntry           entry   = new RouteEntry(name: null, route: route);
            IDirectRouteFactory  factory = CreateStubRouteFactory(entry);
            ControllerDescriptor controllerDescriptor      = CreateStubControllerDescriptor("IgnoreController");
            ActionDescriptor     actionDescriptor          = CreateStubActionDescriptor(controllerDescriptor, "IgnoreAction");
            IReadOnlyCollection <ActionDescriptor> actions = new ActionDescriptor[] { actionDescriptor };
            IInlineConstraintResolver constraintResolver   =
                new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object;

            // Act & Assert
            string expectedMessage = "The route does not have any associated action descriptors. Routing requires " +
                                     "that each direct route map to a non-empty set of actions.";

            Assert.Throws <InvalidOperationException>(() => DefaultDirectRouteProvider.CreateRouteEntry(areaPrefix,
                                                                                                        controllerPrefix, factory, actions, constraintResolver, targetIsAction: false), expectedMessage);
        }
Esempio n. 2
0
        public void CreateRouteEntry_IfDirectRouteProviderReturnsRouteWithHandler_Throws()
        {
            // Arrange
            string areaPrefix       = null;
            string controllerPrefix = null;
            ControllerDescriptor controllerDescriptor = CreateStubControllerDescriptor("IgnoreController");
            ActionDescriptor     actionDescriptor     = CreateStubActionDescriptor(controllerDescriptor, "IgnoreAction");
            Route route = new Route(url: null, routeHandler: null);

            route.DataTokens = new RouteValueDictionary();
            route.DataTokens.Add(RouteDataTokenKeys.Actions, new ActionDescriptor[] { actionDescriptor });
            route.RouteHandler = new Mock <IRouteHandler>(MockBehavior.Strict).Object;
            ActionDescriptor[]  originalActions            = route.GetTargetActionDescriptors();
            RouteEntry          entry                      = new RouteEntry(name: null, route: route);
            IDirectRouteFactory factory                    = CreateStubRouteFactory(entry);
            IReadOnlyCollection <ActionDescriptor> actions = new ActionDescriptor[] { actionDescriptor };
            IInlineConstraintResolver constraintResolver   =
                new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object;

            // Act & Assert
            string expectedMessage = "Direct routing does not support per-route route handlers.";

            Assert.Throws <InvalidOperationException>(() => DefaultDirectRouteProvider.CreateRouteEntry(areaPrefix,
                                                                                                        controllerPrefix, factory, actions, constraintResolver, targetIsAction: false), expectedMessage);
        }
        public void CreateRouteEntry_IfDirectRouteProviderReturnsNull_Throws()
        {
            // Arrange
            string areaPrefix            = null;
            string controllerPrefix      = null;
            IDirectRouteFactory  factory = CreateStubRouteFactory(null);
            ControllerDescriptor controllerDescriptor = CreateStubControllerDescriptor(
                "IgnoreController"
                );
            ActionDescriptor actionDescriptor = CreateStubActionDescriptor(
                controllerDescriptor,
                "IgnoreAction"
                );
            IReadOnlyCollection <ActionDescriptor> actions = new ActionDescriptor[]
            {
                actionDescriptor
            };
            IInlineConstraintResolver constraintResolver =
                new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object;

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () =>
                DefaultDirectRouteProvider.CreateRouteEntry(
                    areaPrefix,
                    controllerPrefix,
                    factory,
                    actions,
                    constraintResolver,
                    targetIsAction: false
                    ),
                "IDirectRouteFactory.CreateRoute must not return null."
                );
        }