Example #1
0
        public async void One_Run_Through_Pipeline_With_No_TransportMessage_Does_Nothing()
        {
            var messageSource = new TestMessageSource <TransportMessage>();
            IIocManagement <TransportMessage> iocManagement =
                new SimpleTestIocManagement(Guid.NewGuid());

            // 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);
            rootServiceProvider.GetService <TestEventHandlerInvocationStats>()
            .HandledEvents.Count.Should().Be(0);

            processedMessage.BiIter(
                right =>
            {
                "Should be right".AssertFail();
            },
                left => left.Should().BeOfType <NoTransportMessageAvailable>()
                );
        }
Example #2
0
        public async void Multiple_Runs_Through_Pipeline_Processes_Provided_Messages()
        {
            int runCount = 10;
            var scopeIds = Enumerable.Range(0, runCount)
                           .Select(i => Guid.NewGuid())
                           .ToList();
            var testEvents = Enumerable.Range(0, runCount)
                             .Select(i => new TestEvent(Guid.NewGuid())).ToList();
            var transportEvents = testEvents
                                  .Select(t => new TransportMessage(t))
                                  .ToArray();

            List <Tuple <Guid, TransportMessage, TestEvent> > expectedHandledEvents =
                scopeIds
                .Zip(transportEvents)
                .Zip(testEvents, (a, b) => Tuple.Create(a.Item1, a.Item2, b))
                .ToList();

            var messageSource = new TestMessageSource <TransportMessage>(transportEvents);
            IIocManagement <TransportMessage> iocManagement =
                new SimpleTestIocManagement(scopeIds.ToArray());

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

            List <Either <IPipelineError, Tuple <TransportMessage, object> > > runResults =
                new List <Either <IPipelineError, Tuple <TransportMessage, object> > >();

            for (var i = 0; i < runCount; i++)
            {
                Either <IPipelineError, Tuple <TransportMessage, object> >
                processedMessage = await MessagePipeline.Run(
                    messageSource,
                    new SimpleMessageTransform(),
                    rootServiceProvider,
                    iocManagement);

                runResults.Add(processedMessage);
            }

            runResults.Count.Should().Be(runCount);
            messageSource.AckCount.Should().Be(runCount);
            rootServiceProvider.GetService <TestEventHandlerInvocationStats>()
            .HandledEvents.Count.Should().Be(runCount);

            rootServiceProvider.GetService <TestEventHandlerInvocationStats>()
            .HandledEvents.Should().BeEquivalentTo(expectedHandledEvents);
        }
Example #3
0
        public async void One_Run_Through_Pipeline_With_TransportMessage_Succeeds()
        {
            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(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(1);
            rootServiceProvider.GetService <TestEventHandlerInvocationStats>()
            .HandledEvents.Single().Should().BeEquivalentTo(
                Tuple.Create(scopeId, transportMessage, testEvent));

            processedMessage.BiIter(
                right =>
            {
                // Sadly, have to cast )-:
                var castTestValue = Tuple.Create(right.Item1,
                                                 (TestEvent)right.Item2);
                castTestValue.Should()
                .BeEquivalentTo(Tuple.Create(transportMessage,
                                             testEvent));
            },
                left => "Should be right".AssertFail()
                );
        }