Esempio n. 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.");
        }
Esempio n. 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");
        }
Esempio n. 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");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }
Esempio n. 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.");
        }