示例#1
0
        public void GivenPipelineThatChangesRequest_WhenHandlingRequest_ThenChangesRequestInPipeline()
        {
            var testHandlerA        = new TestHandler <TestRequestA>();
            var testHandlerB        = new TestHandler <TestRequestA>();
            var testMutationHandler = new TestMutationHandler();
            var testHandlerC        = new TestHandler <TestRequestB>();


            var pipeline = PipelineDefinitionBuilder
                           .StartWith(testHandlerA)
                           .ThenWith(testHandlerB)
                           .ThenWithMutation(testMutationHandler)
                           .ThenWith(testHandlerC)
                           .Build();

            var testRequest = new TestRequestA();
            var context     = new Context();

            pipeline.HandleAsync(testRequest, context);

            Assert.Multiple(() =>
            {
                Assert.That(testHandlerA._request, Is.EqualTo(testRequest));
                Assert.That(testHandlerB._request, Is.EqualTo(testRequest));
                Assert.That(testMutationHandler._request, Is.EqualTo(testRequest));
                Assert.That(testHandlerC._request, Is.Not.EqualTo(testRequest));
                Assert.That(testHandlerC._request, Is.TypeOf <TestRequestB>());
            });
        }
        public async Task GivenPipelineThatChangesRequest_WhenHandlingRequest_ThenChangesRequestInPipeline()
        {
            var testHandlerA        = new TestHandlerA <TestRequestA>();
            var testHandlerB        = new TestHandlerB <TestRequestA>();
            var testMutationHandler = new TestMutationHandler();
            var testHandlerC        = new TestHandlerC <TestRequestB>();

            Dictionary <Type, Object> dictionary = new Dictionary <Type, object>
            {
                [typeof(TestHandlerA <TestRequestA>)] = testHandlerA,
                [typeof(TestHandlerB <TestRequestA>)] = testHandlerB,
                [typeof(TestHandlerC <TestRequestB>)] = testHandlerC,
                [typeof(TestMutationHandler)]         = testMutationHandler,
            };

            PipelineDefinitionBuilder builder = new
                                                PipelineDefinitionBuilder(type => dictionary[type]);


            var pipeline = builder.StartWith <TestHandlerA <TestRequestA>, TestRequestA> ()
                           .ThenWith <TestHandlerB <TestRequestA> >()
                           .ThenWithMutation <TestMutationHandler, TestRequestB>()
                           .ThenWith <TestHandlerC <TestRequestB> >()
                           .Build();

            var testRequest = new TestRequestA();

            await pipeline.HandleAsync(testRequest, new Context());

            Assert.Multiple(() =>
            {
                Assert.That(testHandlerA._request, Is.EqualTo(testRequest));
                Assert.That(testHandlerB._request, Is.EqualTo(testRequest));
                Assert.That(testMutationHandler._request, Is.EqualTo(testRequest));
                Assert.That(testHandlerC._request, Is.Not.EqualTo(testRequest));
                Assert.That(testHandlerC._request, Is.TypeOf <TestRequestB>());
            });
        }