예제 #1
0
        public void create_url_for_a_route_with_two_parameters()
        {
            var url = new RouteInput<SampleViewModel>("my/sample/{InPath}/{AlsoInPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);

            url.Parent.ToRoute().Url.ShouldEqual("my/sample/{InPath}/{AlsoInPath}");
        }
예제 #2
0
        public void create_default_value_for_a_route()
        {
            var url = new RouteInput<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            url.RouteInputFor("InPath").DefaultValue = "something";
            Route route = url.Parent.ToRoute();

            route.Defaults["InPath"].ShouldEqual("something");
        }
예제 #3
0
        public static RouteDefinition Build <T>(string pattern)
        {
            var  parent    = new RouteDefinition(pattern);
            var  input     = new RouteInput <T>(parent);
            Type inputType = typeof(T);

            parent.ApplyInputType(inputType);

            return(parent);
        }
예제 #4
0
        public void create_two_default_values_for_a_route()
        {
            var url = new RouteInput<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.Parent.ToRoute();

            route.Defaults.Count().ShouldEqual(2);
        }
예제 #5
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);
        }
예제 #6
0
 private static void populateRoute(string pattern, Type inputType, IRouteDefinition route)
 {
     parse(pattern, (propName, defaultValue) =>
     {
         PropertyInfo property = inputType.GetProperty(propName);
         if (property == null)
         {
             throw new FubuException(1002, "Url pattern \"{0}\" refers to non-existent property {1} on {2}.",
                                     pattern, propName, inputType.FullName);
         }
         var input = new RouteInput(new SingleProperty(property))
         {
             DefaultValue = defaultValue
         };
         route.AddRouteInput(input, false);
     });
 }
예제 #7
0
        public void should_have_one_default_value_for_route()
        {
            var url = new RouteInput<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);
            url.RouteInputFor("InPath").DefaultValue = "something";
            Route route = url.Parent.ToRoute();

            route.Defaults.Count().ShouldEqual(1);
        }
예제 #8
0
 public void shouldd_not_add_duplicate_input()
 {
     var url = new RouteInput<SampleViewModel>("my/sample");
     url.AddRouteInput(x => x.InPath);
     url.AddRouteInput(x => x.InPath);
     url.AddRouteInput(new RouteParameter(ReflectionHelper.GetAccessor<SampleViewModel>(x=>x.InPath)), false);
     url.RouteParameters.ShouldHaveCount(1);
 }
예제 #9
0
        public void create_url_with_variables_in_querystring_with_parameters()
        {
            var url = new RouteInput<SampleViewModel>("/my/sample/path");
            url.AddQueryInput(x => x.InQueryString);

            var parameters = new RouteParameters<SampleViewModel>();
            parameters[x => x.InQueryString] = "query";

            url.CreateUrlFromParameters(parameters).ShouldEqual("/my/sample/path?InQueryString=query");
        }
예제 #10
0
        public void create_url_with_querystring_and_inputmodel_with_parameters()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddQueryInput(x => x.InQueryString);

            var parameters = new RouteParameters<SampleViewModel>();
            parameters[x => x.InPath] = "5";
            parameters[x => x.InQueryString] = "query";

            url.CreateUrlFromParameters(parameters).ShouldEqual("test/edit/5?InQueryString=query");
        }
예제 #11
0
        public void create_url_with_parameters()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            var parameters = new RouteParameters<SampleViewModel>();
            parameters[x => x.InPath] = "5";

            url.CreateUrlFromParameters(parameters).ShouldEqual("test/edit/5");
        }
예제 #12
0
        public void create_url_with_null_input_model_and_no_default_value_specified_for_optional_input_with_parameters()
        {
            var url = new RouteInput<SampleViewModelWithInputs>("test/edit/{OptionalInput}");
            url.AddRouteInput(x => x.OptionalInput);

            var parameters = new RouteParameters<SampleViewModelWithInputs>();

            url
                .CreateUrlFromParameters(parameters)
                .ShouldEndWith("test/edit/default");
        }
예제 #13
0
        public void create_url_will_escape_the_url_with_parameters()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            var parameters = new RouteParameters<SampleViewModel>();
            parameters[x => x.InPath] = "some text";

            url.CreateUrlFromParameters(parameters).ShouldBe("test/edit/some%20text");
        }
예제 #14
0
 public virtual void AddRouteInput(RouteInput input, bool appendToUrl)
 {
     // do nothing
 }
예제 #15
0
 public void AddRouteInput(RouteInput input, bool appendToUrl)
 {
 }
        public void route_input_should_substitute_method()
        {
            SingleProperty accessor = SingleProperty.Build<SampleViewModel>(x => x.InPath);
            var viewModel = new SampleViewModel
            {
                InPath = "5"
            };
            var routeInput = new RouteInput(accessor);

            routeInput.Substitute(viewModel, "test/edit/{InPath}").ShouldEqual("test/edit/5");
        }
예제 #17
0
        public void create_url_with_input_model_and_no_default_value_specified_for_required_input()
        {
            var url = new RouteInput<SampleViewModelWithInputs>("test/edit/{RequiredInput}");
            url.AddRouteInput(x => x.RequiredInput);

            Exception<FubuException>.ShouldBeThrownBy(() => url.CreateUrlFromInput(new SampleViewModelWithInputs()));
        }
예제 #18
0
        public void create_url_with_multiple_variables_in_querystring()
        {
            var url = new RouteInput<SampleViewModel>("/my/sample/path");
            var props = new List<Expression<Func<SampleViewModel, object>>>
                              {
                                  x => x.InQueryString,
                                  x => x.AlsoInQueryString
                              };
            var inputs = props.Select(x => new RouteParameter(ReflectionHelper.GetAccessor(x)));
            url.AddQueryInputs(inputs);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InQueryString = "query",
                AlsoInQueryString = "alsoquery"
            })
                .ShouldEqual("/my/sample/path?InQueryString=query&AlsoInQueryString=alsoquery");
        }
예제 #19
0
        public void create_url_with_encoded_variables_in_path_by_parameters()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}/{AlsoInPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);

            var parameters = new RouteParameters<SampleViewModel>();
            parameters[x => x.InPath] = "5";
            parameters[x => x.AlsoInPath] = "abc/def&ghi=jkl";

            url.CreateUrlFromParameters(parameters).ShouldEqual("test/edit/5/abc%2Fdef%26ghi%3Djkl");
        }
예제 #20
0
        public void create_url_with_null_input_model_and_no_default_value_specified_for_required_input_with_parameters()
        {
            var url = new RouteInput<SampleViewModelWithInputs>("test/edit/{RequiredInput}");
            url.AddRouteInput(x => x.RequiredInput);

            typeof(FubuException).ShouldBeThrownBy(() => url.CreateUrlFromParameters(null));
        }
예제 #21
0
        public void create_url_with_input_model_and_encoded_variable()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InPath = "abc/def&ghi=jkl"
            }).ShouldEqual("test/edit/abc%2Fdef%26ghi%3Djkl");
        }
예제 #22
0
        public void create_url_with_querystring_and_inputmodel()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddQueryInput(x => x.InQueryString);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InPath = "5",
                InQueryString = "query"
            }).ShouldEqual("test/edit/5?InQueryString=query");
        }
예제 #23
0
        public void will_not_use_query_string_if_there_is_no_value()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddQueryInput(x => x.InQueryString);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InPath = "5",
                InQueryString = null
            }).ShouldEqual("test/edit/5");
        }
예제 #24
0
        public void create_url_with_variables_in_querystring()
        {
            var url = new RouteInput<SampleViewModel>("/my/sample/path");
            url.AddQueryInput(x => x.InQueryString);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InQueryString = "query"
            }).ShouldEqual("/my/sample/path?InQueryString=query");
        }
예제 #25
0
        public void create_url_will_escape_the_url()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InPath = "some text"
            }).ShouldEqual("test/edit/some%20text");
        }
예제 #26
0
        public void does_not_create_default_for_a_simple_parameter()
        {
            var url = new RouteInput<SampleViewModel>("my/sample");
            url.AddRouteInput(x => x.InPath);
            Route route = url.Parent.ToRoute();

            route.Defaults.Count().ShouldEqual(0);
        }
예제 #27
0
        public void create_url_with_input_model()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}");
            url.AddRouteInput(x => x.InPath);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InPath = "5"
            }).ShouldEqual("test/edit/5");
        }
예제 #28
0
        public void should_have_one_default_value_for_a_route_and_does_not_include_querystring_in_route()
        {
            var url = new RouteInput<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.Parent.ToRoute();

            route.Defaults.Count().ShouldEqual(1);
        }
예제 #29
0
        public void create_url_with_input_model_and_default_value_for_required_input()
        {
            var url = new RouteInput<SampleViewModelWithInputs>("test/edit/{RequiredInput}");
            url.AddRouteInput(x => x.RequiredInput);

            url
                .CreateUrlFromInput(new SampleViewModelWithInputs
                {
                    RequiredInput = "a"
                })
                .ShouldEndWith("test/edit/a");
        }
예제 #30
0
 public void to_string_gets_pattern_and_type_full_name()
 {
     var url = new RouteInput<SampleViewModel>("my/sample");
     url.ToString().ShouldEqual("{0} --> {1}".ToFormat(url.Parent.Pattern, typeof(SampleViewModel).FullName));
 }
예제 #31
0
        public void create_url_with_input_model_and_default_value_for_required_input_by_parameters()
        {
            var url = new RouteInput<SampleViewModelWithInputs>("test/edit/{RequiredInput}");
            url.AddRouteInput(x => x.RequiredInput);

            var parameters = new RouteParameters<SampleViewModelWithInputs>();
            parameters[x => x.RequiredInput] = "a";

            url
                .CreateUrlFromParameters(parameters)
                .ShouldEndWith("test/edit/a");
        }
예제 #32
0
 private static void addPropertyInput(IRouteDefinition route, PropertyInfo property)
 {
     var input = new RouteInput(new SingleProperty(property));
     route.AddRouteInput(input, true);
 }
예제 #33
0
        public void create_url_with_multiple_variables_in_path()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}/{AlsoInPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);

            url.CreateUrlFromInput(new SampleViewModel
            {
                InPath = "5",
                AlsoInPath = "some text"
            }).ShouldEqual("test/edit/5/some%20text");
        }
예제 #34
0
 public virtual void AddRouteInput(RouteInput input, bool b)
 {
     // do nothing
 }
예제 #35
0
        public void create_url_with_multiple_variables_in_path_by_parameters()
        {
            var url = new RouteInput<SampleViewModel>("test/edit/{InPath}/{AlsoInPath}");
            url.AddRouteInput(x => x.InPath);
            url.AddRouteInput(x => x.AlsoInPath);

            var parameters = new RouteParameters<SampleViewModel>();
            parameters[x => x.InPath] = "5";
            parameters[x => x.AlsoInPath] = "some text";

            url.CreateUrlFromParameters(parameters).ShouldEqual("test/edit/5/some%20text");
        }