Beispiel #1
0
        public async Task AcknowledgeCallsInnerMessageAcknowledgeIfAcknowledgeForwarderIsNull()
        {
            using var receiver           = new FakeReceiver();
            using var forwardingReceiver = new ForwardingReceiver("foo", receiver, acknowledgeForwarder: null);
            using var message            = new FakeReceiverMessage("Hello, world!");

            var forwardingMessage = new ForwardingReceiverMessage(forwardingReceiver, message);

            await forwardingMessage.AcknowledgeAsync().ConfigureAwait(false);

            message.HandledBy.Should().Be(nameof(IReceiverMessage.AcknowledgeAsync));
        }
        public async Task RollbackCallsInnerMessageRollbackIfRollbackForwarderIsNull()
        {
            var receiver           = new FakeReceiver();
            var forwardingReceiver = new ForwardingReceiver("foo", receiver, rollbackForwarder: null);
            var message            = new FakeReceiverMessage("Hello, world!");

            var forwardingMessage = new ForwardingReceiverMessage(forwardingReceiver, message);

            await forwardingMessage.RollbackAsync();

            message.HandledBy.Should().Be(nameof(IReceiverMessage.RollbackAsync));
        }
Beispiel #3
0
        public async Task RollbackHandlesInnerMessageAccordingToRollbackOutcomeWhenRollbackForwarderIsNotNull(ForwardingOutcome outcome)
        {
            using var forwarder = new FakeSender();

            using var receiver           = new FakeReceiver();
            using var forwardingReceiver = new ForwardingReceiver("foo", receiver, rollbackForwarder: forwarder, rollbackOutcome: outcome);
            using var message            = new FakeReceiverMessage("Hello, world!");

            var forwardingMessage = new ForwardingReceiverMessage(forwardingReceiver, message);

            await forwardingMessage.RollbackAsync().ConfigureAwait(false);

            message.HandledBy.Should().Be($"{outcome}Async");
        }
        public async Task AcknowledgeHandlesInnerMessageAccordingToAcknowledgeOutcomeWhenAcknowledgeForwarderIsNotNull(ForwardingOutcome outcome)
        {
            var forwarder = new FakeSender();

            var receiver           = new FakeReceiver();
            var forwardingReceiver = new ForwardingReceiver("foo", receiver, acknowledgeForwarder: forwarder, acknowledgeOutcome: outcome);
            var message            = new FakeReceiverMessage("Hello, world!");

            var forwardingMessage = new ForwardingReceiverMessage(forwardingReceiver, message);

            await forwardingMessage.AcknowledgeAsync();

            message.HandledBy.Should().Be($"{outcome}Async");
        }
Beispiel #5
0
        public void SettingMessageHandlerSetsTheMessageHandlerOfTheReceiverToAForwardingMessageHandler()
        {
            using var receiver           = new FakeReceiver();
            using var forwardingReceiver = new ForwardingReceiver("foo", receiver);

            var messageHandler = new FakeMessageHandler();

            forwardingReceiver.MessageHandler = messageHandler;

            forwardingReceiver.MessageHandler.Should().BeSameAs(messageHandler);

            receiver.MessageHandler.Should().NotBeSameAs(messageHandler);
            receiver.MessageHandler.Should().BeOfType <ForwardingMessageHandler>();
            ((ForwardingMessageHandler)receiver.MessageHandler).MessageHandler.Should().BeSameAs(messageHandler);
        }
Beispiel #6
0
        public async Task RollbackSendsMessageToRollbackForwarderWhenRollbackForwarderIsNotNull()
        {
            using var forwarder = new FakeSender();

            using var receiver           = new FakeReceiver();
            using var forwardingReceiver = new ForwardingReceiver("foo", receiver, rollbackForwarder: forwarder);
            using var message            = new FakeReceiverMessage("Hello, world!");

            var forwardingMessage = new ForwardingReceiverMessage(forwardingReceiver, message);

            await forwardingMessage.RollbackAsync().ConfigureAwait(false);

            forwarder.SentMessages.Should().ContainSingle();
            forwarder.SentMessages[0].StringPayload.Should().Be("Hello, world!");
        }
        public async Task AcknowledgeSendsMessageToAcknowledgeForwarderWhenAcknowledgeForwarderIsNotNull()
        {
            var forwarder = new FakeSender();

            var receiver           = new FakeReceiver();
            var forwardingReceiver = new ForwardingReceiver("foo", receiver, acknowledgeForwarder: forwarder);
            var message            = new FakeReceiverMessage("Hello, world!");

            var forwardingMessage = new ForwardingReceiverMessage(forwardingReceiver, message);

            await forwardingMessage.AcknowledgeAsync();

            forwarder.SentMessages.Should().ContainSingle();
            forwarder.SentMessages[0].StringPayload.Should().Be("Hello, world!");
        }
Beispiel #8
0
        public async Task TheCallbackPassedToStart3IsInvokedWhenAMessageIsReceived()
        {
            var receiver = new FakeReceiver();

            var received = false;

            receiver.Start(async(r, m) =>
            {
                received = true;
                await m.AcknowledgeAsync();
            });

            await receiver.MessageHandler.OnMessageReceivedAsync(receiver, new FakeReceiverMessage("Hello, world!"));

            Assert.True(received);
        }
Beispiel #9
0
        public async Task TheCallbackPassedToStart1IsInvokedWhenAMessageIsReceived()
        {
            using var receiver = new FakeReceiver();

            var received = false;

            receiver.Start(async m =>
            {
                received = true;
                await m.AcknowledgeAsync().ConfigureAwait(false);
            });

            using var message = new FakeReceiverMessage("Hello, world!");
            await receiver.MessageHandler.OnMessageReceivedAsync(receiver, message).ConfigureAwait(false);

            Assert.True(received);
        }
Beispiel #10
0
        public async Task TheCallbackPassedToStart4IsInvokedWhenAMessageIsReceived()
        {
            var receiver = new FakeReceiver();

            var received = false;

#pragma warning disable CS0618 // Type or member is obsolete
            receiver.Start((r, m) =>
            {
                received = true;
                m.Acknowledge();
            });
#pragma warning restore CS0618 // Type or member is obsolete

            await receiver.MessageHandler.OnMessageReceivedAsync(receiver, new FakeReceiverMessage("Hello, world!"));

            Assert.True(received);
        }
        public async Task OnMessageReceivedCallsInnerHandlerOnMessageReceivedWithForwardingReceiverMessage()
        {
            var receiver           = new FakeReceiver();
            var forwardingReceiver = new ForwardingReceiver("foo", receiver);
            var messageHandler     = new FakeMessageHandler();

            var handler = new ForwardingMessageHandler(forwardingReceiver, messageHandler);

            var message = new FakeReceiverMessage("Hello, world!");

            await handler.OnMessageReceivedAsync(receiver, message);

            messageHandler.ReceivedMessages.Should().ContainSingle();
            messageHandler.ReceivedMessages[0].Receiver.Should().BeSameAs(forwardingReceiver);
            messageHandler.ReceivedMessages[0].Message.Should().BeOfType <ForwardingReceiverMessage>();
            ((ForwardingReceiverMessage)messageHandler.ReceivedMessages[0].Message).Message.Should().BeSameAs(message);
            ((ForwardingReceiverMessage)messageHandler.ReceivedMessages[0].Message).ForwardingReceiver.Should().BeSameAs(forwardingReceiver);
        }