Exemplo n.º 1
0
        public async void BasicPipelineTest()
        {
            TestEvent        testEvent        = new TestEvent(Guid.NewGuid());
            TransportMessage transportMessage = new TransportMessage()
            {
                Message  = JsonConvert.SerializeObject(testEvent),
                Metadata = JObject.FromObject(new
                {
                    messageType = TestEvent.MessageType
                })
            };


            var scopeId = Guid.NewGuid();

            var messageSource =
                new TestMessageSource <TransportMessage>(transportMessage);
            IIocManagement <TransportMessage> iocManagement =
                new TestIocManagement <TransportMessage>(scopeId);

            Dictionary <string, Type> typeLookup = new Dictionary <string, Type>()
            {
                { TestEvent.MessageType, typeof(TestEvent) }
            };

            // Initialize Ioc
            IServiceCollection serviceCollection =
                iocManagement.CreateServiceCollection();
            ServiceProvider rootServiceProvider =
                serviceCollection.BuildServiceProvider();

            Either <IPipelineError, Tuple <TransportMessage, object> >
            processedMessage = await MessagePipeline.Run(
                messageSource,
                new MessageTransform(typeLookup),
                rootServiceProvider,
                iocManagement);

            messageSource.AckCount.Should().Be(1);
            TestEventHandlerInvocationStats.HandledEvents.Single().Should()
            .BeEquivalentTo(
                Tuple.Create <Guid, TransportMessage, TestEvent>(scopeId,
                                                                 transportMessage, testEvent));

            processedMessage.BiIter(
                right =>
            {
                var castTestValue = Tuple.Create(right.Item1,
                                                 (TestEvent)right.Item2);
                castTestValue.Should()
                .BeEquivalentTo(Tuple.Create(transportMessage,
                                             testEvent));
            },
                left => "Should be right".AssertFail()
                );
        }
Exemplo n.º 2
0
        When_Handler_Throws_Exception_It_Is_Returned_In_Result()
        {
            TestEvent        testEvent        = new TestEvent(Guid.NewGuid());
            TransportMessage transportMessage =
                new TransportMessage(testEvent);
            var scopeId = Guid.NewGuid();

            var messageSource =
                new TestMessageSource <TransportMessage>(transportMessage);
            IIocManagement <TransportMessage> iocManagement =
                new SimpleTestIocManagement <ThrowExceptionEventHandler,
                                             TestEvent, TestStats>(scopeId);

            // Initialize Ioc
            IServiceCollection serviceCollection =
                iocManagement.CreateServiceCollection();
            ServiceProvider rootServiceProvider =
                serviceCollection.BuildServiceProvider();

            Either <IPipelineError, Tuple <TransportMessage, object> >
            processedMessage = await MessagePipeline.Run(
                messageSource,
                new SimpleMessageTransform(),
                rootServiceProvider,
                iocManagement);

            messageSource.AckCount.Should().Be(0);
            processedMessage.BiIter(
                right => "Should be left".AssertFail(),
                left =>
            {
                left.Should()
                .BeOfType <MessageHandlingException <TransportMessage,
                                                     object> >();
                left.As <MessageHandlingException <TransportMessage, object>
                         >()
                .Should().BeEquivalentTo(new
                {
                    TransportMessage = transportMessage,
                    DomainMessage    = testEvent
                });
            });
        }