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}"); }
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"); }
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); }
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); }
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); }
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); }); }
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); }
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); }
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"); }
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"); }
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"); }
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"); }
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"); }
public virtual void AddRouteInput(RouteInput input, bool appendToUrl) { // do nothing }
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"); }
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())); }
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"); }
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"); }
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)); }
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"); }
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"); }
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"); }
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"); }
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"); }
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); }
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"); }
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); }
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"); }
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)); }
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"); }
private static void addPropertyInput(IRouteDefinition route, PropertyInfo property) { var input = new RouteInput(new SingleProperty(property)); route.AddRouteInput(input, true); }
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"); }
public virtual void AddRouteInput(RouteInput input, bool b) { // do nothing }
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"); }