示例#1
0
        public void ExecuteOriginalActionToo()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>(set => executed = true);

            collector.Push(new TestMessage());
            collector.PushAndExecute(new OtherMessage(), set => { });

            executed.Should().BeTrue("the original action should have been executed.");
        }
示例#2
0
        public void ThirdPushedMessageIsExecuted()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage, OtherMessage2> collector =
                new MessageCollector <TestMessage, OtherMessage, OtherMessage2>();

            collector.Push(new TestMessage());
            collector.Push(new OtherMessage());
            collector.PushAndExecute(new OtherMessage2(), set => executed = true);

            executed.Should().BeTrue("the set was completed");
        }
示例#3
0
        public void FourthConsumedMessageIsRemovedFromCollector()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage, OtherMessage2, OtherMessage3> collector =
                new MessageCollector <TestMessage, OtherMessage, OtherMessage2, OtherMessage3>();

            collector.Push(new TestMessage());
            collector.Push(new OtherMessage());
            collector.Push(new OtherMessage2());
            collector.PushAndExecute(new OtherMessage3(), set => executed = true);

            executed.Should().BeTrue("the set was completed");
        }
示例#4
0
        public void ExecutePushedMessageIfSetIsFullWithDecorator()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>();

            collector.Push(new TestMessage());
            collector.PushAndExecute(OtherDecorator.Decorate(new OtherMessage()), set =>
            {
                executed = true;
            });

            executed.Should().BeTrue("this set should have been executed immediately.");
        }
示例#5
0
        public void PushAndExecuteStoresMessages()
        {
            int executed = 0;
            MessageCollector <TestMessage, OtherMessage> collector =
                new MessageCollector <TestMessage, OtherMessage>(set => executed++);

            collector.Push(new TestMessage());
            collector.PushAndExecute(new OtherMessage(), set =>
            {
            });
            collector.Push(new TestMessage());

            executed.Should().Be(2, "push and execute should store the other message.");
        }
示例#6
0
        public void ExecutePushedMessageOnlyOnce()
        {
            int executed = 0;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>();

            collector.Push(new TestMessage());
            collector.PushAndExecute(new OtherMessage(), set =>
            {
                executed++;
            });
            collector.Push(new TestMessage());

            executed.Should().Be(1, "the executed action should not have been executed twice.");
        }
示例#7
0
        public void ExecutePushedMessageIfSetIsFull()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>();

            collector.Push(new TestMessage());
            bool result = collector.PushAndExecute(new OtherMessage(), set =>
            {
                executed = true;
            });

            executed.Should().BeTrue("this set should have been executed immediately.");
            result.Should().BeTrue("result should be true if it was executed.");
        }
示例#8
0
        public void ConsumedMessageIsRemovedFromCollectorUsingPushAndExecute()
        {
            int executed = 0;
            MessageCollector <TestMessage, OtherMessage> collector =
                new MessageCollector <TestMessage, OtherMessage>(set => executed++);

            collector.Push(new TestMessage());
            collector.PushAndExecute(new OtherMessage(), set =>
            {
                set.MarkAsConsumed(set.Message2);
            });
            collector.Push(new TestMessage());

            executed.Should().Be(1, "other message should have been eliminated.");
        }
示例#9
0
        public void ExecutePushedMessageIfSetIsFilledLater()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>();

            using Timer timer = new Timer(state =>
            {
                executed.Should().BeFalse("The set should not execute before pushing second message.");
                collector.Push(new TestMessage());
            }, null, 200,
                                          Timeout.Infinite);
            collector.PushAndExecute(new OtherMessage(), set =>
            {
                executed = true;
            });

            executed.Should().BeTrue("this set should have been executed after the timer goes of.");
        }
示例#10
0
        public void CancelPushAndExecuteAndAfterwardsPushDoesNotExecuteAction()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>();

            using CancellationTokenSource source = new CancellationTokenSource();
            using Timer timer = new Timer(state =>
            {
                source.Cancel();
            }, null, 200,
                                          Timeout.Infinite);
            collector.PushAndExecute(new OtherMessage(), set =>
            {
                executed = true;
            }, source.Token);
            collector.Push(new TestMessage());

            executed.Should().BeFalse("execution was canceled.");
        }
示例#11
0
        public void CancelPushAndExecute()
        {
            bool executed = false;
            MessageCollector <TestMessage, OtherMessage> collector = new MessageCollector <TestMessage, OtherMessage>();

            using CancellationTokenSource source = new CancellationTokenSource();
            using Timer timer = new Timer(state =>
            {
                source.Cancel();
            }, null, 200,
                                          Timeout.Infinite);
            bool result = collector.PushAndExecute(new OtherMessage(), set =>
            {
                executed = true;
            }, source.Token);

            executed.Should().BeFalse("execution was canceled.");
            result.Should().BeFalse("result should be false when canceled.");
        }