public async Task RunHandlerThrowsArgumentNullExceptionWhenMessageIsNull()
        {
            // Arrange
            var handler = new SitefinityMessageHandler(processor, logger, correlationIdProvider);

            // Act
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await handler.Run(null).ConfigureAwait(false)).ConfigureAwait(false);
        }
Example #2
0
        public async Task RunHandlerThrowsArgumentNullExceptionWhenMessageIsNull()
        {
            // Arrange
            var processor = A.Fake <IMessageProcessor>();
            var messagePropertiesService = A.Fake <IMessagePropertiesService>();
            var logger = A.Fake <ILogger>();

            // Act
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await SitefinityMessageHandler.Run((Message)null, processor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
Example #3
0
        public async Task RunHandlerThrowsArgumentOutOfRangeExceptionWhenMessageContentTypeIsInvalid()
        {
            // Arrange
            var message   = CreateBaseMessage(contentType: (MessageContentType)999);
            var processor = A.Fake <IMessageProcessor>();
            var messagePropertiesService = A.Fake <IMessagePropertiesService>();
            var logger = A.Fake <ILogger>();

            // Act
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await SitefinityMessageHandler.Run(message, processor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
Example #4
0
        public async Task RunHandlerThrowsArgumentExceptionWhenMessageBodyIsEmpty()
        {
            // Arrange
            var message   = new Message(Encoding.ASCII.GetBytes(string.Empty));
            var processor = A.Fake <IMessageProcessor>();
            var messagePropertiesService = A.Fake <IMessagePropertiesService>();
            var logger = A.Fake <ILogger>();

            // Act
            await Assert.ThrowsAsync <ArgumentException>(async() => await SitefinityMessageHandler.Run(message, processor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task RunHandlerThrowsArgumentNullExceptionWhenMessageIsNull()
        {
            // Arrange
            var processor = A.Fake <IMessageProcessor>();
            var messagePropertiesService = A.Fake <IMessagePropertiesService>();
            var logService               = A.Fake <ILogService>();
            var correlationIdProvider    = A.Fake <ICorrelationIdProvider>();
            var sitefinityMessageHandler = new SitefinityMessageHandler(processor, messagePropertiesService, logService, correlationIdProvider);

            // Act
            await Assert.ThrowsAsync <ArgumentNullException>(async() => await sitefinityMessageHandler.Run(null).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task RunHandlerThrowsArgumentOutOfRangeExceptionWhenMessageActionIsInvalid()
        {
            // Arrange
            var message   = CreateBaseMessage(messageAction: (MessageAction)999);
            var processor = A.Fake <IMessageProcessor>();
            var messagePropertiesService = A.Fake <IMessagePropertiesService>();
            var logService               = A.Fake <ILogService>();
            var correlationIdProvider    = A.Fake <ICorrelationIdProvider>();
            var sitefinityMessageHandler = new SitefinityMessageHandler(processor, messagePropertiesService, logService, correlationIdProvider);

            // Act
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await sitefinityMessageHandler.Run(message).ConfigureAwait(false)).ConfigureAwait(false);
        }
Example #7
0
        public async Task SitefinityMessageHandlerReturnsExceptionWhenEmptyServiceBusMessageSupplied()
        {
            // arrange
            const MessageAction      messageAction      = MessageAction.Published;
            const MessageContentType messageContentType = MessageContentType.Pages;
            var serviceBusMessage = new Message(Encoding.ASCII.GetBytes(string.Empty));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            // act
            await Assert.ThrowsAsync <ArgumentException>(async() => await SitefinityMessageHandler.Run(serviceBusMessage, messageProcessor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
        public async Task RunHandlerCallsMessagePreProcessorWhenMessageIsNotNull()
        {
            // Arrange
            var model             = A.Fake <PatchEnvironmentsModel>();
            var message           = JsonConvert.SerializeObject(model);
            var serviceBusMessage = new Message(Encoding.ASCII.GetBytes(message));

            var handler = new SitefinityMessageHandler(processor, logger, correlationIdProvider);

            // Act
            await handler.Run(serviceBusMessage).ConfigureAwait(false);

            A.CallTo(() => processor.Process(A <Message> .Ignored)).MustHaveHappenedOnceExactly();
        }
        public async Task SitefinityMessageHandlerReturnsSuccessForSegmentUpdated(HttpStatusCode expectedResult)
        {
            // arrange
            const MessageAction      messageAction      = MessageAction.Published;
            const MessageContentType messageContentType = MessageContentType.WorkingHoursDetails;
            const long sequenceNumber    = 123;
            var        model             = A.Fake <PatchWorkingHoursDetailModel>();
            var        message           = JsonConvert.SerializeObject(model);
            var        serviceBusMessage = new Message(Encoding.ASCII.GetBytes(message));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            A.CallTo(() => messagePropertiesService.GetSequenceNumber(serviceBusMessage)).Returns(sequenceNumber);
            A.CallTo(() => messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, messageAction)).Returns(expectedResult);

            // act
            await sitefinityMessageHandler.Run(serviceBusMessage).ConfigureAwait(false);

            // assert
            A.CallTo(() => messagePropertiesService.GetSequenceNumber(serviceBusMessage)).MustHaveHappenedOnceExactly();
            A.CallTo(() => messageProcessor.ProcessAsync(message, sequenceNumber, messageContentType, messageAction)).MustHaveHappenedOnceExactly();
        }
Example #10
0
        public async Task SitefinityMessageHandlerReturnsExceptionWhenMessageActionIsInvalid()
        {
            // arrange
            const int messageAction = -1;
            const MessageContentType messageContentType = MessageContentType.Pages;
            var model             = A.Fake <ContentPageMessage>();
            var message           = JsonConvert.SerializeObject(model);
            var serviceBusMessage = new Message(Encoding.ASCII.GetBytes(message));

            serviceBusMessage.UserProperties.Add("ActionType", messageAction);
            serviceBusMessage.UserProperties.Add("CType", messageContentType);
            serviceBusMessage.UserProperties.Add("Id", Guid.NewGuid());

            // act
            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await SitefinityMessageHandler.Run(serviceBusMessage, messageProcessor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
        }
Example #11
0
        public async Task RunHandlerLogsWarningWhenMessageProcessorReturnsError()
        {
            // Arrange
            var message = CreateBaseMessage();
            var logger  = A.Fake <ILogger>();

            var processor = A.Fake <IMessageProcessor>();

            A.CallTo(() => processor.ProcessAsync(A <string> .Ignored, A <long> .Ignored, A <MessageContentType> .Ignored, A <MessageAction> .Ignored)).Returns(HttpStatusCode.InternalServerError);

            var messagePropertiesService = A.Fake <IMessagePropertiesService>();

            A.CallTo(() => messagePropertiesService.GetSequenceNumber(A <Message> .Ignored)).Returns(123);

            // Act
            await SitefinityMessageHandler.Run(message, processor, messagePropertiesService, logger).ConfigureAwait(false);

            // Assert
            A.CallTo(() => logger.Log(LogLevel.Warning, 0, A <FormattedLogValues> .Ignored, A <Exception> .Ignored, A <Func <object, Exception, string> > .Ignored)).MustHaveHappenedOnceExactly();
        }
Example #12
0
 public async Task SitefinityMessageHandlerReturnsExceptionWhenNullServiceBusMessageSupplied()
 {
     // act
     await Assert.ThrowsAsync <ArgumentNullException>(async() => await SitefinityMessageHandler.Run(null, messageProcessor, messagePropertiesService, logger).ConfigureAwait(false)).ConfigureAwait(false);
 }
 public async Task RunHandlerThrowsArgumentNullExceptionWhenMessageIsNull()
 {
     // Act
     await Assert.ThrowsAsync <ArgumentNullException>(async() => await sitefinityMessageHandler.Run(null).ConfigureAwait(false)).ConfigureAwait(false);
 }