예제 #1
0
        public void GivenCompletedUserMessage_ShouldInvokeMessageReceivedImmediately()
        {
            var mailboxHandler    = new TestMailboxHandler();
            var userMailbox       = new UnboundedMailboxQueue();
            var systemMessages    = new UnboundedMailboxQueue();
            var mailboxStatistics = new TestMailboxStatistics();
            var mailbox           = new DefaultMailbox(systemMessages, userMailbox, mailboxStatistics);

            mailbox.RegisterHandlers(mailboxHandler, mailboxHandler);

            var msg1 = new TestMessage();

            msg1.TaskCompletionSource.SetResult(0);

            mailbox.PostUserMessage(msg1);
            Assert.Contains(msg1, mailboxStatistics.Posted);
        }
        public void GivenCompletedSystemMessageThrewException_ShouldNotInvokeMessageReceived()
        {
            var mailboxHandler    = new TestMailboxHandler();
            var userMailbox       = new UnboundedMailboxQueue();
            var systemMessages    = new UnboundedMailboxQueue();
            var mailboxStatistics = new TestMailboxStatistics();
            var mailbox           = new DefaultMailbox(systemMessages, userMailbox, mailboxStatistics);

            mailbox.RegisterHandlers(mailboxHandler, mailboxHandler);

            var msg1 = new TestMessage();

            msg1.TaskCompletionSource.SetException(new Exception());

            mailbox.PostSystemMessage(msg1);

            Assert.DoesNotContain(msg1, mailboxStatistics.Received);
        }
        public async Task GivenNonCompletedSystemMessageThrewException_ShouldNotInvokeMessageReceived()
        {
            var mailboxHandler    = new TestMailboxHandler();
            var userMailbox       = new UnboundedMailboxQueue();
            var systemMessages    = new UnboundedMailboxQueue();
            var mailboxStatistics = new TestMailboxStatistics();
            var mailbox           = new DefaultMailbox(systemMessages, userMailbox, mailboxStatistics);

            mailbox.RegisterHandlers(mailboxHandler, mailboxHandler);

            var msg1 = new TestMessage();

            mailbox.PostSystemMessage(msg1);

            Action resumeMailboxTrigger = () => msg1.TaskCompletionSource.SetException(new Exception());
            await mailboxHandler.ResumeMailboxProcessingAndWaitAsync(resumeMailboxTrigger)
            .ConfigureAwait(false);

            Assert.DoesNotContain(msg1, mailboxStatistics.Received);
        }