コード例 #1
0
        public async Task Should_map_null_if_there_are_no_parameters()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Params(null, null, null))
                               .WithRequestData("")
                               .AddQuerystringParameter("param1")
                               .AddQuerystringParameter("param2");

            var binder = new FormBinder(requestGraph.ValueMappers,
                                        requestGraph.Configuration);

            await binder.Bind(requestGraph.GetRequestBinderContext());

            requestGraph.ActionArguments.ShouldOnlyContain(null, null, null);
        }
コード例 #2
0
        public async Task Should_map_parameters_that_were_not_passed_as_null()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Params(null, null, null))
                               .WithRequestData("param1=value1")
                               .AddQuerystringParameter("param1")
                               .AddValueMapper1(x => x.Values.First());

            var binder = new FormBinder(requestGraph.ValueMappers,
                                        requestGraph.Configuration);

            await binder.Bind(requestGraph.GetRequestBinderContext());

            requestGraph.ActionArguments.ShouldOnlyContain(null, "value1", null);
        }
コード例 #3
0
        public async Task Should_map_multiple_parameters_with_the_same_name_as_an_array()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.MultiParams(null))
                               .WithRequestData("param1=value1&param1=value2")
                               .AddQuerystringParameter("param1")
                               .AddValueMapper1(x => x.Values);

            var binder = new FormBinder(requestGraph.ValueMappers,
                                        requestGraph.Configuration);

            await binder.Bind(requestGraph.GetRequestBinderContext());

            requestGraph.ActionArguments[0].CastTo <string[]>()
            .ShouldOnlyContain("value1", "value2");
        }
コード例 #4
0
        public async Task Should_not_use_a_mapper_that_doesnt_apply_at_runtime()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Params(null, null, null))
                               .WithRequestData("param1=value1&param2=value2")
                               .AddQuerystringParameter("param1")
                               .AddQuerystringParameter("param2")
                               .AddValueMapper1(x => x.Values.First() + "mapper1", instanceAppliesTo: x => false)
                               .AddValueMapper2(x => x.Values.First() + "mapper2");

            var binder = new FormBinder(requestGraph.ValueMappers,
                                        requestGraph.Configuration);

            await binder.Bind(requestGraph.GetRequestBinderContext());

            requestGraph.ActionArguments.ShouldOnlyContain(null, "value1mapper2", "value2mapper2");

            requestGraph.ValueMapper1.AppliesToCalled.ShouldBeTrue();
            requestGraph.ValueMapper1.MapCalled.ShouldBeFalse();

            requestGraph.ValueMapper2.AppliesToCalled.ShouldBeTrue();
            requestGraph.ValueMapper2.MapCalled.ShouldBeTrue();
        }
コード例 #5
0
        public async Task Should_bind_form_values()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Params(null, null, null))
                               .WithRequestData("param1=value1&param2=value2")
                               .AddQuerystringParameter("param1")
                               .AddQuerystringParameter("param2")
                               .AddValueMapper1(x => x.Values.First());

            var binder = new FormBinder(requestGraph.ValueMappers,
                                        requestGraph.Configuration);

            await binder.Bind(requestGraph.GetRequestBinderContext());

            requestGraph.ActionArguments.ShouldOnlyContain(null, "value1", "value2");

            requestGraph.ValueMapper1.AppliesToContext.RequestContext.ShouldNotBeNull();
            requestGraph.ValueMapper1.AppliesToContext.Parameter.ShouldNotBeNull();
            requestGraph.ValueMapper1.AppliesToContext.Values.ShouldNotBeNull();

            requestGraph.ValueMapper1.MapContext.RequestContext.ShouldNotBeNull();
            requestGraph.ValueMapper1.MapContext.Parameter.ShouldNotBeNull();
            requestGraph.ValueMapper1.MapContext.Values.ShouldNotBeNull();
        }