Ejemplo n.º 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));
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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!");
        }
        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);
        }