コード例 #1
0
        public void add_multiple_http_constraints()
        {
            var route = new RouteDefinition("something");
            route.AddHttpMethodConstraint("get");
            route.AddHttpMethodConstraint("POST");

            route.GetHttpMethodConstraints().ShouldHaveTheSameElementsAs("GET", "POST");
        }
コード例 #2
0
        public IRouteDefinition Build(ActionCall call)
        {
            var className = call.HandlerType.Name.ToLower()
                .Replace("endpoints", "")
                .Replace("endpoint", "")
                
                .Replace("controller", "");

            RouteDefinition route = null;
            if (RouteDefinition.VERBS.Any(x => x.EqualsIgnoreCase(call.Method.Name)))
            {
                route = new RouteDefinition(className);
                route.AddHttpMethodConstraint(call.Method.Name.ToUpper());
            }
            else
            {
                route = new RouteDefinition("{0}/{1}".ToFormat(className, call.Method.Name.ToLowerInvariant()));
            }

            if (call.InputType() != null)
            {
                if (call.InputType().CanBeCastTo<ResourcePath>())
                {
                    ResourcePath.AddResourcePathInputs(route);
                }
                else
                {
                    AddBasicRouteInputs(call, route);
                }
            }

            return route;
        }
コード例 #3
0
 public void Configure(BehaviorGraph graph)
 {
     var route = new RouteDefinition("");
     route.AddHttpMethodConstraint("GET");
     var chain = new BehaviorChain { Route = route };
     chain.AddToEnd(new RedirectNode());
     graph.AddChain(chain);
     graph.Services.AddService(this);
 }
コード例 #4
0
        public IRouteDefinition Build(ActionCall call)
        {
            Type viewModelType = call.HandlerType.GetGenericArguments()[0];

            var route = new RouteDefinition(viewModelType.Name.Replace("ViewModel","").ToLower());
            route.ApplyInputType(viewModelType);
            route.AddHttpMethodConstraint("POST");

            return route;
        }
コード例 #5
0
        public IRouteDefinition Build(ActionCall call)
        {
            // Later on we need to put in real plural naming.
            string pattern = call.HandlerType.GetGenericArguments()[0].Name.Replace("ViewModel", "") + "es";

            var route = new RouteDefinition(pattern.ToLower());
            route.ApplyInputType(call.InputType());
            route.AddHttpMethodConstraint("GET");

            return route;
        }
コード例 #6
0
        public void Configure(BehaviorGraph graph)
        {
            if (!graph.Behaviors.Any(x => x.Route != null && x.GetRoutePattern().IsEmpty()))
            {
                var action = ActionCall.For<DefaultHome>(x => x.GoToDiagnostics());
                var continuer = new ContinuationNode();

                var route = new RouteDefinition("");
                route.AddHttpMethodConstraint("GET");
                var chain = new BehaviorChain {Route = route};
                chain.AddToEnd(action);
                chain.AddToEnd(continuer);

                graph.AddChain(chain);
            }
        }
コード例 #7
0
        public IRouteDefinition Build(ActionCall call)
        {
            string pattern = call.HandlerType.GetGenericArguments()[0].Name.Replace("ViewModel", "");

            var route = new RouteDefinition(pattern.ToLower());
            route.Append("{Id}");

            if (call.InputType().Name.StartsWith("Edit`"))
            {
                route.Append("edit");
            }
            else if (call.InputType().Name.StartsWith("Get`"))
            {
                route.Append("view");
            }

            route.ApplyInputType(call.InputType());
            route.AddHttpMethodConstraint("GET");

            return route;
        }
コード例 #8
0
        public void create_route_with_http_constraints()
        {
            var route = new RouteDefinition("something");
            route.AddHttpMethodConstraint("Get");
            route.AddHttpMethodConstraint("POST");

            route.ToRoute().Constraints.Single().Value.ShouldBeOfType<HttpMethodConstraint>()
                .AllowedMethods.ShouldHaveTheSameElementsAs("GET", "POST");
        }
コード例 #9
0
 public void responds_to_get_if_GET_is_explicitly_allowed()
 {
     var route = new RouteDefinition("something");
     route.AddHttpMethodConstraint("Get");
     route.AddHttpMethodConstraint("POST");
     route.RespondsToGet().ShouldBeTrue();
 }
コード例 #10
0
 public void does_not_respond_to_get_if_http_methods_are_explicitly_defined_and_get_is_not_allowed()
 {
     var route = new RouteDefinition("something");
     route.AddHttpMethodConstraint("POST");
     route.RespondsToGet().ShouldBeFalse();
 }