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); }
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); }
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¶m1=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"); }
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¶m2=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(); }
public async Task Should_bind_form_values() { var requestGraph = RequestGraph .CreateFor <Handler>(h => h.Params(null, null, null)) .WithRequestData("param1=value1¶m2=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(); }