コード例 #1
0
        public void DenyWhileChangingOfRunningMessageConsumer()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
            var factory = new TestRouterFactory(new Waiter(waitablesCount: 1), messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.Consume(TestRouterHelper.HandleMessage);
                consumer.While = null;
            }
        }
コード例 #2
0
        public void CheckOrderTest()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
            var waiter  = new Waiter(waitablesCount: 1);
            var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.Sequence(0, TestRouterHelper.MessagesCountToGenerate)));

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.Consume(TestRouterHelper.HandleMessage);
                waiter.Wait(true);
            }
        }
コード例 #3
0
        public void SwallowExceptionTest()
        {
            const int errorMessageIndex         = 5;
            var       waiter                    = new Waiter(waitablesCount: 1);
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex, swallowException: true);
            var factory = new TestRouterFactory(waiter, messages => messages.CheckOrder(TestRouterHelper.SequenceExcluding(0, TestRouterHelper.MessagesCountToGenerate, errorMessageIndex)));

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.Consume(TestRouterHelper.HandleMessage);
                waiter.Wait(true);
            }
        }
コード例 #4
0
        public void CheckIsRunningTest()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(TestRouterHelper.SourceName, TestRouterHelper.MessagesCountToGenerate);
            var waiter  = new Waiter(waitablesCount: 1);
            var factory = new TestRouterFactory(waiter, messages => {});

            using (IMessageConsumer <TestMessage> consumer = factory.CreateConsumer(source))
            {
                consumer.IsRunning.Should(Be.False);
                consumer.Consume(TestRouterHelper.HandleMessage);
                consumer.IsRunning.Should(Be.True);
                waiter.Wait();
                consumer.IsRunning.Should(Be.True);
            }
        }
コード例 #5
0
        public void RouterShouldHandleMessagesIfTagIsNotProvided()
        {
            IMessageSource <TestMessage> source = MessageGenerator.CreateSource(string.Empty, 5);
            var waiter  = new Waiter(1);
            var factory = new TestRouterFactory(waiter, messages => { });

            using (IMessageConsumer <TestMessage> router = factory.CreateRouter(source, factory, m => m.Tag))
            {
                var messagesHandled = 0;
                waiter.Register(router);
                router.While = m => TestMessage.IsNotStopMessage(string.Empty, m);
                router.Consume(message => messagesHandled++);
                waiter.Wait(true);

                messagesHandled.Should(Be.EqualTo(6));
                //Do not receive message from queue, if router handles message by itself. Let the handle logic do this.
                ((TestMessageRouter)router).ReceiveCallCount.Should(Be.EqualTo(0));
            }
        }