public void BuildRoute_ValidatesConstraintType_InvalidType()
        {
            // Arrange
            var actions = GetActions();
            var builder = new DirectRouteBuilder(actions, targetIsAction: true);

            var constraint  = new Uri("http://localhost/");
            var constraints = new TRouteValueDictionary();

            constraints.Add("custom", constraint);

            builder.Constraints = constraints;
            builder.Template    = "c/{id}";

#if ASPNETWEBAPI
            string expectedMessage =
                "The constraint entry 'custom' on the route with route template 'c/{id}' "
                + "must have a string value or be of a type which implements 'System.Web.Http.Routing.IHttpRouteConstraint'.";
#else
            string expectedMessage =
                "The constraint entry 'custom' on the route with route template 'c/{id}' "
                + "must have a string value or be of a type which implements 'System.Web.Routing.IRouteConstraint'.";
#endif

            // Act & Assert
            Assert.Throws <InvalidOperationException>(() => builder.Build(), expectedMessage);
        }
Ejemplo n.º 2
0
        private static IHttpRoute CreateDirectRoute(string template,
                                                    IEnumerable <ReflectedHttpActionDescriptor> actions)
        {
            DirectRouteBuilder builder = new DirectRouteBuilder(actions);

            builder.Template = template;
            return(builder.Build().Route);
        }
Ejemplo n.º 3
0
        private static IHttpRoute CreateDirectRoute(string template,
                                                    IReadOnlyCollection <ReflectedHttpActionDescriptor> actions)
        {
            DirectRouteBuilder builder = new DirectRouteBuilder(actions, targetIsAction: true);

            builder.Template = template;
            return(builder.Build().Route);
        }
Ejemplo n.º 4
0
        HttpRouteEntry IDirectRouteProvider.CreateRoute(DirectRouteProviderContext context)
        {
            Contract.Assert(context != null);

            DirectRouteBuilder builder = context.CreateBuilder(Template);

            Contract.Assert(builder != null);

            builder.Name  = Name;
            builder.Order = Order;
            return(builder.Build());
        }
        public void BuildRoute_ValidatesConstraintType_StringRegex()
        {
            // Arrange
            var actions = GetActions();
            var builder = new DirectRouteBuilder(actions, targetIsAction: true);

            var constraint = "product|products";
            var constraints = new TRouteValueDictionary();
            constraints.Add("custom", constraint);
            builder.Constraints = constraints;

            // Act
            var routeEntry = builder.Build();

            // Assert
            Assert.NotNull(routeEntry.Route.Constraints["custom"]);
        }
        public void BuildRoute_ValidatesConstraintType_StringRegex()
        {
            // Arrange
            var actions = GetActions();
            var builder = new DirectRouteBuilder(actions, targetIsAction: true);

            var constraint  = "product|products";
            var constraints = new TRouteValueDictionary();

            constraints.Add("custom", constraint);
            builder.Constraints = constraints;

            // Act
            var routeEntry = builder.Build();

            // Assert
            Assert.NotNull(routeEntry.Route.Constraints["custom"]);
        }
        public void BuildRoute_ValidatesConstraintType_InvalidType()
        {
            // Arrange
            var actions = GetActions();
            var builder = new DirectRouteBuilder(actions, targetIsAction: true);

            var constraint = new Uri("http://localhost/");
            var constraints = new TRouteValueDictionary();
            constraints.Add("custom", constraint);

            builder.Constraints = constraints;
            builder.Template = "c/{id}";

#if ASPNETWEBAPI
            string expectedMessage =
                "The constraint entry 'custom' on the route with route template 'c/{id}' " +
                "must have a string value or be of a type which implements 'System.Web.Http.Routing.IHttpRouteConstraint'.";
#else
            string expectedMessage =
                "The constraint entry 'custom' on the route with route template 'c/{id}' " +
                "must have a string value or be of a type which implements 'System.Web.Routing.IRouteConstraint'.";
#endif

            // Act & Assert
            Assert.Throws<InvalidOperationException>(() => builder.Build(), expectedMessage);
        }
 private static IHttpRoute CreateDirectRoute(string template,
     IReadOnlyCollection<ReflectedHttpActionDescriptor> actions)
 {
     DirectRouteBuilder builder = new DirectRouteBuilder(actions, targetIsAction: true);
     builder.Template = template;
     return builder.Build().Route;
 }