public void should_return_allowed_route_methods()
        {
            _route.AddHttpMethodConstraint("POST");
            _route.AddHttpMethodConstraint("PUT");

            var result = ActionCallMapper.getRouteVerbs(_route).ToArray();

            result.Count().ShouldEqual(2);
            result.Contains("POST");
            result.Contains("PUT");
        }
Esempio n. 2
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable <string> properties, Action <string> log)
        {
            log("Method name interpreted by the MethodToUrlBuilder");
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();

            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }

            for (int i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    log(" - adding route input for property " + part);
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }
            }

            route.Append(parts.Join("/"));
        }
Esempio n. 3
0
        public static void Alter(IRouteDefinition route, string methodName, IEnumerable<string> properties, Action<string> log)
        {
            log("Method name interpreted by the MethodToUrlBuilder");
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();
            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }

            for (int i = 0; i < parts.Count; i++)
            {
                var part = parts[i];
                if (properties.Contains(part))
                {
                    log(" - adding route input for property " + part);
                    parts[i] = "{" + part + "}";
                }
                else
                {
                    parts[i] = part.ToLower();
                }

            }

            route.Append(parts.Join("/"));
        }
        public void Apply(ActionCall call, IRouteDefinition routeDefinition)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                routeDefinition.Trace("Adding route constraint {0} based on filter [{1}]", filter.Method,
                                      filter.Description);

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
Esempio n. 5
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                observer.RecordCallStatus(call,
                    "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description));

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
Esempio n. 6
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition, IConfigurationObserver observer)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                observer.RecordCallStatus(call,
                                          "Adding route constraint {0} based on filter [{1}]".ToFormat(filter.Method, filter.Description));

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
Esempio n. 7
0
        public void Apply(ActionCall call, IRouteDefinition routeDefinition)
        {
            _httpMethodFilters.Where(x => x.Filter(call)).Each(filter =>
            {
                routeDefinition.Trace("Adding route constraint {0} based on filter [{1}]", filter.Method,
                                      filter.Description);

                routeDefinition.AddHttpMethodConstraint(filter.Method);
            });
        }
Esempio n. 8
0
        public static List<string> AddHttpConstraints(IRouteDefinition route, string methodName)
        {
            var parts = methodName.Replace("___", "-").Replace("__", "_^").Split('_').ToList();

            var method = parts.First().ToUpper();
            if (RouteDefinition.VERBS.Contains(method))
            {
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return parts;
        }
Esempio n. 9
0
        public static List<string> AddHttpConstraints(IRouteDefinition route, string methodName, Action<string> log)
        {
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();
            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return parts;
        }
Esempio n. 10
0
        public static List <string> AddHttpConstraints(IRouteDefinition route, string methodName)
        {
            var parts = methodName.Replace("___", "-").Replace("__", "_^").Split('_').ToList();

            var method = parts.First().ToUpper();

            if (RouteDefinition.VERBS.Contains(method))
            {
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return(parts);
        }
Esempio n. 11
0
        public static List <string> AddHttpConstraints(IRouteDefinition route, string methodName, Action <string> log)
        {
            var parts = methodName.Split('_').ToList();

            var method = parts.First().ToUpper();

            if (RouteDefinition.VERBS.Contains(method))
            {
                log(" - adding Http method constraint {0}".ToFormat(method));
                route.AddHttpMethodConstraint(method);
                parts.RemoveAt(0);
            }
            return(parts);
        }
 private static void ConstrainToHttpMethod(
     IRouteDefinition route, ActionCallBase call, IEnumerable<Configuration.HttpConstraintPattern> patterns)
 {
     Func<Configuration.Segment, string> getName = s =>
     {
         switch (s)
         {
             case Configuration.Segment.Namespace: return call.HandlerType.Namespace;
             case Configuration.Segment.Class: return call.HandlerType.Name;
             case Configuration.Segment.Method: return call.Method.Name;
         } return null;
     };
     patterns.Where(x => x.Regex.IsMatch(getName(x.Type))).ToList().
                 ForEach(x => route.AddHttpMethodConstraint(x.Method));
 }
Esempio n. 13
0
        private static void ConstrainToHttpMethod(
            IRouteDefinition route, ActionCallBase call, IEnumerable <Configuration.HttpConstraintPattern> patterns)
        {
            Func <Configuration.Segment, string> getName = s =>
            {
                switch (s)
                {
                case Configuration.Segment.Namespace: return(call.HandlerType.Namespace);

                case Configuration.Segment.Class: return(call.HandlerType.Name);

                case Configuration.Segment.Method: return(call.Method.Name);
                }
                return(null);
            };

            patterns.Where(x => x.Regex.IsMatch(getName(x.Type))).ToList().
            ForEach(x => route.AddHttpMethodConstraint(x.Method));
        }
Esempio n. 14
0
 public static void Modification(IRouteDefinition route)
 {
     route.Replace("Feed", "");
     route.AddHttpMethodConstraint("GET");
 }