Example #1
0
        public async Task WebhookContentProcessorProcessContentAsyncForUpdateReturnsNoContent()
        {
            // Arrange
            const HttpStatusCode expectedResponse          = HttpStatusCode.NoContent;
            var expectedValidApiContentModel               = BuildValidPagesApiContentModel();
            ContentPageModel?expectedValidContentPageModel = default;
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhookContentProcessor();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidApiContentModel);
            A.CallTo(() => FakeMapper.Map <ContentPageModel?>(A <CmsApiDataModel> .Ignored)).Returns(expectedValidContentPageModel);

            // Act
            var result = await service.ProcessContentAsync(url, ContentIdForCreate).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <CmsApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <ContentPageModel>(A <CmsApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventGridService.CompareAndSendEventAsync(A <ContentPageModel> .Ignored, A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
        public async Task WebhooksServiceProcessContentAsyncForUpdateReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResponse    = HttpStatusCode.OK;
            var expectedValidContentItemApiDataModel = BuildValidContentItemApiDataModel();
            var expectedValidContentItemModel        = BuildValidContentItemModel();
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhooksService();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <SharedContentItemApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidContentItemApiDataModel);
            A.CallTo(() => FakeMapper.Map <SharedContentItemModel>(A <SharedContentItemApiDataModel> .Ignored)).Returns(expectedValidContentItemModel);
            A.CallTo(() => FakeSharedContentItemDocumentService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedValidContentItemModel);
            A.CallTo(() => FakeSharedContentItemDocumentService.UpsertAsync(A <SharedContentItemModel> .Ignored)).Returns(HttpStatusCode.OK);

            // Act
            var result = await service.ProcessContentAsync(url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <SharedContentItemApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <SharedContentItemModel>(A <SharedContentItemApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeSharedContentItemDocumentService.UpsertAsync(A <SharedContentItemModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeSharedContentItemDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Example #3
0
        public async Task WebhooksServiceProcessMessageAsyncContentUpdateConfigurationSetReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResponse         = HttpStatusCode.OK;
            var expectedValidConfigurationSetApiDataModel = BuildValidConfigurationSetApiDataModel();
            var expectedValidConfigurationSetModel        = BuildValidConfigurationSetModel();
            var url     = "https://somewhere.com";
            var service = BuildWebhooksService();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidConfigurationSetApiDataModel);
            A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).Returns(expectedValidConfigurationSetModel);
            A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).Returns(HttpStatusCode.OK);

            // Act
            var result = await service.ProcessMessageAsync(WebhookCacheOperation.CreateOrUpdate, Guid.NewGuid(), ContentIdForConfigurationSetUpdate, url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <EmailApiDataModel>(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeCmsApiService.GetItemAsync <ConfigurationSetApiDataModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeMapper.Map <ConfigurationSetModel>(A <ConfigurationSetApiDataModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeConfigurationSetDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Example #4
0
        public async Task WebhooksServiceProcessMessageAsyncContentThrowsErrorForInvalidUrl()
        {
            // Arrange
            var expectedValidEmailApiDataModel = BuildValidEmailApiDataModel();
            var url     = "/somewhere.com";
            var service = BuildWebhooksService();

            A.CallTo(() => FakeCmsApiService.GetItemAsync <EmailApiDataModel>(A <Uri> .Ignored)).Returns(expectedValidEmailApiDataModel);

            // Act
            await Assert.ThrowsAsync <InvalidDataException>(async() => await service.ProcessMessageAsync(WebhookCacheOperation.CreateOrUpdate, Guid.NewGuid(), ContentIdForEmailCreate, url).ConfigureAwait(false)).ConfigureAwait(false);
        }
Example #5
0
        public async Task WebhooksServiceProcessMessageAsyncNoneOptionReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.BadRequest;
            var url     = "https://somewhere.com";
            var service = BuildWebhooksService();

            // Act
            var result = await service.ProcessMessageAsync(WebhookCacheOperation.None, Guid.NewGuid(), ContentIdForEmailCreate, url).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <EmailApiDataModel>(A <Uri> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeConfigurationSetDocumentService.UpsertAsync(A <ConfigurationSetModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeConfigurationSetDocumentService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Example #6
0
        public async Task WebhookContentProcessorProcessContentAsyncForUpdateReturnsNoContent()
        {
            // Arrange
            const HttpStatusCode expectedResponse          = HttpStatusCode.NoContent;
            var expectedValidApiContentModel               = BuildValidCmsApiSharedContentModel();
            ContentPageModel?expectedValidContentPageModel = default;
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhookContentProcessor();
            CmsApiSharedContentModel content;

            A.CallTo(() => FakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).Returns(Task.FromResult <CmsApiSharedContentModel>(null));

            // Act
            var result = await service.ProcessContentAsync(url, SharedId).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeCmsApiService.GetItemAsync <CmsApiSharedContentModel>(A <Uri> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeEventMessageService.UpdateAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.CreateAsync(A <CmsApiSharedContentModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.AreEqual(expectedResponse, result);
        }