public void Should_catch_errors() { //arrange var nextProcessor = new Mock <IMessageProcessor>(); var messageStateHandler = new Mock <IMessageStateHandler <TestCommand> >(); nextProcessor.Setup(x => x.ProcessAsync(messageStateHandler.Object, CancellationToken.None)) .Throws <Exception>(); var logger = new Mock <ILog>(); var middleware = new ErrorHandlingMiddleware(logger.Object); //act & assert middleware.Invoking(async x => await x.ProcessAsync(messageStateHandler.Object, Mock.Of <IPipelineInformation>(), nextProcessor.Object, CancellationToken.None)).Should().NotThrow(); }
public void Should_not_throw_when_abandon_message_on_errors_fails() { //arrange var nextProcessor = new Mock <IMessageProcessor>(); var messageStateHandler = new Mock <IMessageStateHandler <TestCommand> >(); messageStateHandler.Setup(x => x.AbandonByErrorAsync(It.IsAny <Exception>())).Throws <Exception>(); nextProcessor.Setup(x => x.ProcessAsync(messageStateHandler.Object, CancellationToken.None)) .Throws <Exception>(); var logger = new Mock <ILog>(); var middleware = new ErrorHandlingMiddleware(logger.Object); //act middleware.Invoking(async x => await x.ProcessAsync(messageStateHandler.Object, Mock.Of <IPipelineInformation>(), nextProcessor.Object, CancellationToken.None)).Should().NotThrow(); //assert logger.Verify(x => x.Error(It.IsAny <Exception>(), "Failed to abandon message {@TestCommand}", It.IsAny <TestCommand>()), Times.Once); }