Exemple #1
0
        public void GetActionDirectRoutes_IfDirectRouteProviderReturnsRouteWithHandler_Throws()
        {
            // Arrange
            var action = CreateStubActionDescriptor("IgnoreAction");

            HttpRouteValueDictionary dataTokens = new HttpRouteValueDictionary
            {
                { RouteDataTokenKeys.Actions, new HttpActionDescriptor[] { action } }
            };
            HttpMessageHandler handler = new Mock <HttpMessageHandler>(MockBehavior.Strict).Object;
            HttpRoute          route   = new HttpRoute(null, null, null, dataTokens, handler);
            RouteEntry         entry   = new RouteEntry(name: null, route: route);
            var factories = new[] { CreateStubRouteFactory(entry) };

            var constraintResolver = new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object;

            var provider = new AccessibleDirectRouteProvider();

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

            Assert.Throws <InvalidOperationException>(
                () => provider.GetActionDirectRoutes(action, factories, constraintResolver),
                expectedMessage);
        }
Exemple #2
0
        public void GetActionDirectRoutes_IfDirectRouteProviderReturnsRouteWithEmptyActionDescriptors_Throws()
        {
            // Arrange
            HttpRouteValueDictionary dataTokens = new HttpRouteValueDictionary
            {
                { RouteDataTokenKeys.Actions, new HttpActionDescriptor[0] }
            };
            HttpRoute  route     = new HttpRoute(null, null, null, dataTokens);
            RouteEntry entry     = new RouteEntry(name: null, route: route);
            var        factories = new[] { CreateStubRouteFactory(entry) };

            var action             = CreateStubActionDescriptor("IgnoreAction");
            var constraintResolver =
                new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object;

            var provider = new AccessibleDirectRouteProvider();

            // 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>(
                () => provider.GetActionDirectRoutes(action, factories, constraintResolver),
                expectedMessage
                );
        }
Exemple #3
0
        public void GetActionDirectRoutes_IfDirectRouteProviderReturnsNull_Throws()
        {
            // Arrange
            var factories          = new[] { CreateStubRouteFactory(null) };
            var action             = CreateStubActionDescriptor("IgnoreAction");
            var constraintResolver = new Mock <IInlineConstraintResolver>(MockBehavior.Strict).Object;

            var provider = new AccessibleDirectRouteProvider();

            // Act & Assert
            Assert.Throws <InvalidOperationException>(
                () => provider.GetActionDirectRoutes(action, factories, constraintResolver),
                "IDirectRouteFactory.CreateRoute must not return null.");
        }