public async Task RunHandlerThrowsArgumentNullExceptionWhenMessageIsNull() { // Arrange var preProcessor = new MessagePreProcessor(processor, logService, propertiesService); // Act await Assert.ThrowsAsync <ArgumentNullException>(async() => await preProcessor.Process(null).ConfigureAwait(false)).ConfigureAwait(false); }
public async Task RunHandlerThrowsArgumentOutOfRangeExceptionWhenMessageContentTypeIsInvalid() { // Arrange var message = CreateBaseMessage(contentType: (MessageContentType)999); var preProcessor = new MessagePreProcessor(processor, logService, propertiesService); // Act await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await preProcessor.Process(message).ConfigureAwait(false)).ConfigureAwait(false); }
public async Task RunHandlerThrowsArgumentExceptionWhenMessageBodyIsEmpty() { // Arrange var message = new Message(Encoding.ASCII.GetBytes(string.Empty)); var preProcessor = new MessagePreProcessor(processor, logService, propertiesService); // Act await Assert.ThrowsAsync <ArgumentException>(async() => await preProcessor.Process(message).ConfigureAwait(false)).ConfigureAwait(false); }
public async Task RunHandlerLogsWarningWhenMessageProcessorReturnsError() { // Arrange var message = CreateBaseMessage(); var fakeProcessor = A.Fake <IMessageProcessor>(); A.CallTo(() => fakeProcessor.ProcessAsync(A <string> .Ignored, A <long> .Ignored, A <MessageContentType> .Ignored, A <MessageActionType> .Ignored)).Returns(HttpStatusCode.InternalServerError); var messagePropertiesService = A.Fake <IMessagePropertiesService>(); A.CallTo(() => messagePropertiesService.GetSequenceNumber(A <Message> .Ignored)).Returns(123); var preProcessor = new MessagePreProcessor(fakeProcessor, logService, propertiesService); // Act await preProcessor.Process(message).ConfigureAwait(false); // Assert A.CallTo(() => logService.LogWarning(A <string> .Ignored)).MustHaveHappenedOnceExactly(); }
public async Task RunHandlerLogsInformationWhenMessageProcessorReturnsSuccess(HttpStatusCode status) { // Arrange var message = CreateBaseMessage(); var logger = A.Fake <ILogService>(); var processor = A.Fake <IMessageProcessor>(); A.CallTo(() => processor.ProcessAsync(A <string> .Ignored, A <long> .Ignored, A <MessageContentType> .Ignored, A <MessageActionType> .Ignored)).Returns(status); var messagePropertiesService = A.Fake <IMessagePropertiesService>(); A.CallTo(() => messagePropertiesService.GetSequenceNumber(A <Message> .Ignored)).Returns(123); // Act var messagePreProcessor = new MessagePreProcessor(processor, logger, messagePropertiesService); await messagePreProcessor.Process(message).ConfigureAwait(false); // Assert A.CallTo(() => logger.LogInformation(A <string> .Ignored)).MustHaveHappenedOnceExactly(); }