예제 #1
0
        public async Task Should_bind_reader_result_with_the_first_matching_reader()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Get(null))
                               .WithRequestParameter("request")
                               .AddRequestReader1(x => "reader1".ToTaskResult <object>())
                               .AddRequestReader2(x => "reader2".ToTaskResult <object>());
            var binder = new ReaderBinder(requestGraph.RequestReaders, requestGraph.Configuration);
            var requestReaderContext = requestGraph.GetRequestBinderContext();

            await binder.Bind(requestReaderContext);

            requestGraph.ActionArguments.ShouldOnlyContain("reader1");

            requestGraph.RequestReader1.AppliesToCalled.ShouldBeTrue();
            requestGraph.RequestReader1.AppliesToContext.RequestContext
            .ShouldEqual(requestReaderContext.RequestContext);
            requestGraph.RequestReader1.ReadCalled.ShouldBeTrue();
            requestGraph.RequestReader1.ReadContext.RequestContext
            .ShouldEqual(requestReaderContext.RequestContext);

            requestGraph.RequestReader2.AppliesToCalled.ShouldBeTrue();
            requestGraph.RequestReader2.AppliesToContext.RequestContext
            .ShouldEqual(requestReaderContext.RequestContext);
            requestGraph.RequestReader2.ReadCalled.ShouldBeFalse();
        }
예제 #2
0
        public async Task Should_not_bind_if_no_reader_found()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Get(null))
                               .WithRequestParameter("request")
                               .AddValueMapper1(x => $"{x.Values.First()}mapper");
            var binder = new ReaderBinder(requestGraph.RequestReaders, requestGraph.Configuration);

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

            requestGraph.ActionArguments.ShouldOnlyContain(null);

            requestGraph.ValueMapper1.MapCalled.ShouldBeFalse();
        }
예제 #3
0
        public async Task Should_not_bind_with_reader_instance_that_does_not_apply()
        {
            var requestGraph = RequestGraph
                               .CreateFor <Handler>(h => h.Get(null))
                               .WithRequestParameter("request")
                               .AddRequestReader1(x => "reader1".ToTaskResult <object>(),
                                                  instanceAppliesTo: x => false)
                               .AddRequestReader2(x => "reader2".ToTaskResult <object>())
                               .AddValueMapper1(x => x.Values.First());

            var binder = new ReaderBinder(requestGraph.RequestReaders, requestGraph.Configuration);

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

            requestGraph.ActionArguments.ShouldOnlyContain("reader2");

            requestGraph.RequestReader1.AppliesToCalled.ShouldBeTrue();
            requestGraph.RequestReader1.ReadCalled.ShouldBeFalse();

            requestGraph.RequestReader2.AppliesToCalled.ShouldBeTrue();
            requestGraph.RequestReader2.ReadCalled.ShouldBeTrue();
        }