Ejemplo n.º 1
0
        public void add_http_method_constraint()
        {
            var route = new RouteDefinition("something");
            route.AddHttpMethodConstraint("get");

            route.GetHttpMethodConstraints().ShouldHaveTheSameElementsAs("GET");
        }
Ejemplo n.º 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;
        }
        public void create_url_for_a_route_with_two_parameters()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample/{InPath}/{AlsoInPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);

            url.ToRoute().Url.ShouldEqual("my/sample/{InPath}/{AlsoInPath}");
        }
Ejemplo n.º 4
0
        public static void AddBasicRouteInputs(ActionCall call, RouteDefinition route)
        {
            call.InputType()
                .GetProperties()
                .Where(x => x.HasAttribute<RouteInputAttribute>())
                .Each(prop => route.Append("{" + prop.Name + "}"));

            route.ApplyInputType(call.InputType());
        }
        public void add_constraint_to_route_with_model()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample");
            var constraintToAdd = new HttpMethodConstraint("POST");
            url.AddRouteConstraint("httpMethod", constraintToAdd);
            Route route = url.ToRoute();

            route.Constraints["httpMethod"].ShouldEqual(constraintToAdd);
        }
        public void create_default_value_for_a_route()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            url.RouteInputFor("InPath").DefaultValue = "something";
            Route route = url.ToRoute();

            route.Defaults["InPath"].ShouldEqual("something");
        }
Ejemplo n.º 7
0
        public static RouteDefinition <T> Build <T>(string pattern)
        {
            var  route     = new RouteDefinition <T>(pattern);
            Type inputType = typeof(T);

            populateRoute(pattern, inputType, route);

            return(route);
        }
Ejemplo n.º 8
0
        public static RouteDefinition Build <T>(string pattern)
        {
            var  parent    = new RouteDefinition(pattern);
            Type inputType = typeof(T);

            parent.ApplyInputType(inputType);

            return(parent);
        }
 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);
 }
Ejemplo n.º 10
0
        public void create_url_with_input_model()
        {
            var url = new RouteDefinition<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            url.CreateUrl(new SampleViewModel
            {
                InPath = "5"
            }).ShouldEqual("/test/edit/5");
        }
        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;
        }
Ejemplo n.º 12
0
        public void add_constraint_to_route_with_model()
        {
            var parent = new RouteDefinition("my/sample");
            parent.Input = new RouteInput<SampleViewModel>(parent);
            var constraintToAdd = new HttpMethodConstraint("POST");
            parent.AddRouteConstraint("httpMethod", constraintToAdd);
            Route route = parent.ToRoute();

            route.Constraints["httpMethod"].ShouldEqual(constraintToAdd);
        }
Ejemplo n.º 13
0
        public void create_url_will_escape_the_url()
        {
            var url = new RouteDefinition<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            url.CreateUrl(new SampleViewModel
            {
                InPath = "some text"
            }).ShouldEqual("/test/edit/some%20text");
        }
Ejemplo n.º 14
0
        public static IRouteDefinition Build(Type inputType, string pattern)
        {
            var  parent    = new RouteDefinition(pattern);
            Type routeType = typeof(RouteInput <>).MakeGenericType(inputType);
            var  input     = Activator.CreateInstance(routeType, parent) as IRouteInput;

            populateRoute(pattern, inputType, input);
            parent.Input = input;

            return(parent);
        }
        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;
        }
Ejemplo n.º 16
0
        public void create_two_default_values_for_a_route()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);
            url.RouteInputFor("InPath").DefaultValue = "something";
            url.RouteInputFor("AlsoInPath").DefaultValue = "something else";
            Route route = url.ToRoute();

            route.Defaults.Count().ShouldEqual(2);
        }
Ejemplo n.º 17
0
        public void create_url_with_input_model_and_default_value_for_optional_input()
        {
            var url = new RouteDefinition<SampleViewModelWithInputs>("test/edit/{OptionalInput}");
            url.AddRouteInput(x => x.OptionalInput);

            url
                .CreateUrl(new SampleViewModelWithInputs
                {
                    OptionalInput = "a"
                })
                .ShouldEndWith("/test/edit/a");
        }
Ejemplo n.º 18
0
        public static RouteDefinition Build <T>(string pattern)
        {
            var  parent    = new RouteDefinition(pattern);
            var  input     = new RouteInput <T>(parent);
            Type inputType = typeof(T);

            populateRoute(pattern, inputType, input);

            parent.Input = input;

            return(parent);
        }
Ejemplo n.º 19
0
        public void adds_the_route_aliases()
        {
            var route1 = new RouteDefinition("something/else");
            var route2 = new RouteDefinition("again/something/else");

            var chain = theGraph.BehaviorFor<RouteAliasController>(x => x.get_something());
            var routes = chain.AdditionalRoutes;

            routes.ShouldHaveCount(2);
            routes.ShouldContain(route1);
            routes.ShouldContain(route2);
        }
        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);
            }
        }
        private BehaviorGraph setupActions()
        {
            var registry = new FubuRegistry();
            registry.Actions.IncludeType<RouteAliasAction1>();

            registry.Configure(x =>
            {
                theRouteDefinitionAlias = new RouteDefinition("{Client}/");
                theRouteDefinitionAlias.Input = MockRepository.GenerateMock<IRouteInput>();
                theRouteDefinitionAlias.Input.Stub(_ => _.Rank).Return(5);

                x.BehaviorFor<RouteAliasAction1>(_ => _.M1()).As<RoutedChain>().AddRouteAlias(theRouteDefinitionAlias);
            });

            return BehaviorGraph.BuildFrom(registry);
        }
Ejemplo n.º 22
0
        public void sets_the_full_url()
        {
            var fullUrl = "this/is/a/test";

            var route = new RouteDefinition("blah");
            route.ApplyInputType(typeof(object));
            
            theChain.Route = route;
            
            theUrlResolver.Stub(x => x.UrlFor(theInput, theChain)).Return(fullUrl);
            theResolver.Stub(x => x.Find(theSearch)).Return(theChain);

            theRequest.Attach(theServices);

            theRequest.Url.ShouldEqual(fullUrl);
        }
        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;
        }
Ejemplo n.º 24
0
        public void does_not_create_default_for_a_simple_parameter()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            Route route = url.ToRoute();

            route.Defaults.Count().ShouldEqual(0);
        }
Ejemplo n.º 25
0
        public void should_not_have_constraints_by_default()
        {
            var url = new RouteDefinition("my/sample");
            Route route = url.ToRoute();

            route.Constraints.ShouldBeNull();
        }
Ejemplo n.º 26
0
        public void should_have_one_default_value_for_route()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);
            url.RouteInputFor("InPath").DefaultValue = "something";
            Route route = url.ToRoute();

            route.Defaults.Count().ShouldEqual(1);
        }
Ejemplo n.º 27
0
        public void should_have_one_default_value_for_a_route_and_does_not_include_querystring_in_route()
        {
            var url = new RouteDefinition<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            url.AddQueryInput(x => x.InQueryString);
            url.RouteInputFor("InPath").DefaultValue = "something";
            url.QueryInputFor("InQueryString").DefaultValue = "querysomething";
            Route route = url.ToRoute();

            route.Defaults.Count().ShouldEqual(1);
        }
Ejemplo n.º 28
0
 protected bool Equals(RouteDefinition other)
 {
     return string.Equals(_pattern, other._pattern, StringComparison.OrdinalIgnoreCase)
         && _constraints.SequenceEqual(other._constraints)
         && GetHttpMethodConstraints().SequenceEqual(other.GetHttpMethodConstraints());
 }
Ejemplo n.º 29
0
 public void SetUp()
 {
     thePattern = "here/there/{Name}/{Age}";
     route = RouteBuilder.Build<InputModel>(thePattern);
 }
Ejemplo n.º 30
0
        public void create_url_with_variables_in_querystring()
        {
            var url = new RouteDefinition<SampleViewModel>("/my/sample/path");
            url.AddQueryInput(x => x.InQueryString);

            url.CreateUrl(new SampleViewModel
            {
                InQueryString = "query"
            }).ShouldEqual("/my/sample/path?InQueryString=query");
        }
Ejemplo n.º 31
0
        public void create_url_with_querystring_and_inputmodel()
        {
            var url = new RouteDefinition<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddQueryInput(x => x.InQueryString);

            url.CreateUrl(new SampleViewModel
            {
                InPath = "5",
                InQueryString = "query"
            }).ShouldEqual("/test/edit/5?InQueryString=query");
        }
Ejemplo n.º 32
0
 protected bool Equals(RouteDefinition other)
 {
     return(string.Equals(_pattern, other._pattern, StringComparison.OrdinalIgnoreCase) &&
            _constraints.SequenceEqual(other._constraints) &&
            GetHttpMethodConstraints().SequenceEqual(other.GetHttpMethodConstraints()));
 }
Ejemplo n.º 33
0
 public void SetUp()
 {
     thePattern = "here/there/{Name}/{Age}";
     route = RouteBuilder.Build(typeof (InputModel), thePattern).ShouldBeOfType<RouteDefinition<InputModel>>();
 }
Ejemplo n.º 34
0
        public void prepend_to_route()
        {
            var route = new RouteDefinition("my/sample");
            route.Prepend("area");

            route.Pattern.ShouldEqual("area/my/sample");
        }
Ejemplo n.º 35
0
 public RouteInput(RouteDefinition parent)
 {
     _parent = parent;
 }
Ejemplo n.º 36
0
        public void prepend_to_route_takes_care_of_stupid_trailing_leading_slashes()
        {
            var route = new RouteDefinition("my/sample");
            route.Prepend("area/");

            route.Pattern.ShouldEqual("area/my/sample");
        }