public async Task ShouldProperlyExecuteFailurePipelineInReverseOrderWhenMessageHandlingServiceThrowsException() { var argsMock = new Mock <BasicDeliverEventArgs>(); var consumingServiceMock = new Mock <IConsumingService>(); var exception = new Exception(); var messageHandlingServiceMock = new Mock <IMessageHandlingService>(); messageHandlingServiceMock.Setup(x => x.HandleMessageReceivingEvent(argsMock.Object, consumingServiceMock.Object)) .ThrowsAsync(exception); var filterOrderMap = new Dictionary <int, int>(); var firstFilter = new StubMessageHandlingExceptionFilter(1, filterOrderMap); var secondFilter = new StubMessageHandlingExceptionFilter(2, filterOrderMap); var thirdFilter = new StubMessageHandlingExceptionFilter(3, filterOrderMap); var exceptionFilters = new List <IMessageHandlingExceptionFilter> { firstFilter, secondFilter, thirdFilter }; var service = CreateService( messageHandlingServiceMock.Object, Enumerable.Empty <IMessageHandlingFilter>(), exceptionFilters); await service.Execute(argsMock.Object, consumingServiceMock.Object); messageHandlingServiceMock.Verify(x => x.HandleMessageProcessingFailure(exception, argsMock.Object, consumingServiceMock.Object), Times.Once); Assert.Equal(1, filterOrderMap[thirdFilter.FilterNumber]); Assert.Equal(2, filterOrderMap[secondFilter.FilterNumber]); Assert.Equal(3, filterOrderMap[firstFilter.FilterNumber]); }
public async Task ShouldProperlyExecuteFailurePipelineInReverseOrderWhenMessageHandlingFilterThrowsException() { var argsMock = new Mock <BasicDeliverEventArgs>(); var queueServiceMock = new Mock <IQueueService>(); var messageHandlingServiceMock = new Mock <IMessageHandlingService>(); var exception = new Exception(); var handlingFilter = new Mock <IMessageHandlingFilter>(); handlingFilter.Setup(x => x.Execute(It.IsAny <Func <BasicDeliverEventArgs, IQueueService, Task> >())) .Throws(exception); var handlingFilters = new List <IMessageHandlingFilter> { handlingFilter.Object }; var filterOrderMap = new Dictionary <int, int>(); var firstFilter = new StubMessageHandlingExceptionFilter(1, filterOrderMap); var secondFilter = new StubMessageHandlingExceptionFilter(2, filterOrderMap); var thirdFilter = new StubMessageHandlingExceptionFilter(3, filterOrderMap); var exceptionFilters = new List <IMessageHandlingExceptionFilter> { firstFilter, secondFilter, thirdFilter }; var service = CreateService( messageHandlingServiceMock.Object, handlingFilters, exceptionFilters); await service.Execute(argsMock.Object, queueServiceMock.Object); messageHandlingServiceMock.Verify(x => x.HandleMessageProcessingFailure(exception, argsMock.Object, queueServiceMock.Object), Times.Once); Assert.Equal(1, filterOrderMap[thirdFilter.FilterNumber]); Assert.Equal(2, filterOrderMap[secondFilter.FilterNumber]); Assert.Equal(3, filterOrderMap[firstFilter.FilterNumber]); }