示例#1
0
        public async Task HandleFailureAsync_Test()
        {
            //Arrange
            var receiver = Substitute.For <IMessageReceiver>();
            var sender   = Substitute.For <IMessageSender>();

            var message = CreateMessage();

            //Act
            await _sut.HandleFailureAsync(new TestMessageContext(message, receiver, sender), CancellationToken.None);

            //Assert
            await receiver.Received().DeferAsync(Arg.Is(message.SystemProperties.LockToken)).ConfigureAwait(false);

            await sender.SendAsync(Arg.Any <Message>()).ConfigureAwait(false);

            await receiver.DidNotReceiveWithAnyArgs().DeadLetterAsync(null).ConfigureAwait(false);
        }
示例#2
0
        public async Task HandleFailureAsync_Test()
        {
            //Arrange
            var receiver = Substitute.For <IMessageReceiver>();

            //Act
            await _sut.HandleFailureAsync(new MessageContext(new Message(), receiver), CancellationToken.None);

            //Assert
            await receiver.DidNotReceiveWithAnyArgs().CompleteAsync(null).ConfigureAwait(false);

            await receiver.DidNotReceiveWithAnyArgs().DeferAsync(null).ConfigureAwait(false);

            await receiver.DidNotReceiveWithAnyArgs().AbandonAsync(null).ConfigureAwait(false);

            await receiver.DidNotReceiveWithAnyArgs().DeadLetterAsync(null).ConfigureAwait(false);
        }
示例#3
0
        public async Task ProcessMessageContextAsync(MessageContext context, CancellationToken cancellationToken = default)
        {
            try
            {
                await CheckForDeferredMessageAsync(context).ConfigureAwait(false);

                await _messageProcessor.ProcessMessageAsync(context.Message, cancellationToken).ConfigureAwait(false);

                await context.MessageReceiver.CompleteAsync(context.Message.SystemProperties.LockToken)
                .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                if (await TryCompleteOnExceptionAsync(context, exception) || await TryAbandonOnExceptionAsync(context, exception))
                {
                    return;
                }

                await _failurePolicy.HandleFailureAsync(context, cancellationToken).ConfigureAwait(false);
            }
        }
示例#4
0
        public async Task ProcessMessageContextAsync_FailurePolicy_Handle_Test()
        {
            //Arrange
            var message = CreateMessage();
            var context = new TestMessageContext(message, _messageReceiver, _messageSender);

            _failurePolicy.CanHandle(Arg.Any <Exception>()).Returns(true);
            _messageProcessor.ProcessMessageAsync(Arg.Any <Message>(), Arg.Any <CancellationToken>())
            .Throws(new Exception());

            //Act
            await _sut.ProcessMessageContextAsync(context, CancellationToken.None).ConfigureAwait(false);

            //Assert
            await _messageProcessor.Received().ProcessMessageAsync(Arg.Is(message), Arg.Is(CancellationToken.None))
            .ConfigureAwait(false);

            await _messageReceiver.DidNotReceiveWithAnyArgs().CompleteAsync(null).ConfigureAwait(false);

            await _messageReceiver.DidNotReceiveWithAnyArgs().AbandonAsync(null).ConfigureAwait(false);

            await _failurePolicy.HandleFailureAsync(Arg.Is(context), Arg.Is(CancellationToken.None))
            .ConfigureAwait(false);
        }