Example #1
0
        public async Task WebhookContentProcessorDeletePageLocationAsyncForCreateReturnsSuccess()
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.OK;
            var exptectedGuidList = new List <Guid> {
                PageLocationIdForCreate, Guid.NewGuid()
            };
            var expectedValidContentPageModel = BuildValidContentPageModel();
            var service = BuildWebhookContentProcessor();

            A.CallTo(() => FakeContentCacheService.GetContentIdsContainingContentItemId(A <Guid> .Ignored)).Returns(exptectedGuidList);
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(expectedValidContentPageModel);
            A.CallTo(() => FakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).Returns(HttpStatusCode.OK);
            A.CallTo(() => FakeContentCacheService.RemoveContentItem(A <Guid> .Ignored, A <Guid> .Ignored));

            // Act
            var result = await service.DeleteContentItemAsync(PageLocationIdForDelete).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentCacheService.GetContentIdsContainingContentItemId(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => FakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceOrMore();
            A.CallTo(() => FakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeContentCacheService.RemoveContentItem(A <Guid> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly();

            Assert.Equal(expectedResponse, result);
        }
Example #2
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);
        }
Example #3
0
        public async Task PagesControllerPutReturnsAlreadyReportedForUpdate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.AlreadyReported;
            var existingModel = A.Fake <ContentPageModel>();

            existingModel.SequenceNumber = 123;

            var modelToUpsert = A.Fake <ContentPageModel>();

            modelToUpsert.SequenceNumber = existingModel.SequenceNumber - 1;

            var controller = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns(existingModel);

            // Act
            var result = await controller.Update(modelToUpsert).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedResponse, statusCodeResult.StatusCode);

            controller.Dispose();
        }
        public async Task WebhookContentProcessorProcessContentItemAsyncReturnsNoContentWhenNoContentIds()
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.NoContent;
            var exptectedEmptyGuidList            = new List <Guid>();
            var url     = new Uri("https://somewhere.com");
            var service = BuildWebhookContentProcessor();

            A.CallTo(() => FakeContentCacheService.GetContentIdsContainingContentItemId(A <Guid> .Ignored)).Returns(exptectedEmptyGuidList);

            // Act
            var result = await service.ProcessContentItemAsync(url, ContentItemIdForUpdate).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentCacheService.GetContentIdsContainingContentItemId(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakePageLocatonUpdater.FindAndUpdateAsync(A <Uri> .Ignored, A <Guid> .Ignored, A <List <PageLocationModel> > .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeContentItemUpdater.FindAndUpdateAsync(A <Uri> .Ignored, A <Guid> .Ignored, A <List <ContentItemModel> > .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.UpdateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.CreateAsync(A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeEventGridService.CompareAndSendEventAsync(A <ContentPageModel> .Ignored, A <ContentPageModel> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
        public async Task PagesControllerPostReturnsSuccessForCreate(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.Created;
            var contentPageModel = A.Fake <ContentPageModel>();
            var controller       = BuildPagesController(mediaTypeName);

            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored)).Returns((ContentPageModel)null);
            A.CallTo(() => FakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).Returns(expectedResponse);

            // Act
            var result = await controller.Create(contentPageModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly();
            var okResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedResponse, okResult.StatusCode);

            controller.Dispose();
        }
Example #6
0
        public async Task WebhookContentProcessorDeleteContentItemAsyncForUpdateReturnsNoContent()
        {
            // Arrange
            const HttpStatusCode expectedResponse = HttpStatusCode.NoContent;
            var exptectedEmptyGuidList            = new List <Guid>();
            var service = BuildWebhookContentProcessor();

            A.CallTo(() => FakeContentCacheService.GetContentIdsContainingContentItemId(A <Guid> .Ignored)).Returns(exptectedEmptyGuidList);

            // Act
            var result = await service.DeleteContentItemAsync(ContentItemIdForDelete).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentCacheService.GetContentIdsContainingContentItemId(A <Guid> .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(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeContentCacheService.RemoveContentItem(A <Guid> .Ignored, A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }
Example #7
0
        public async Task WebhookContentProcessorDeleteContentAsyncForCreateReturnsNoContent()
        {
            // Arrange
            const HttpStatusCode expectedResponse     = HttpStatusCode.NoContent;
            ContentPageModel?    nullContentPageModel = null;
            var service = BuildWebhookContentProcessor();

            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(nullContentPageModel);
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).Returns(expectedResponse);
            A.CallTo(() => FakeContentCacheService.Remove(A <Guid> .Ignored));

            // Act
            var result = await service.DeleteContentAsync(ContentIdForDelete).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeEventMessageService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => FakeEventGridService.SendEventAsync(A <WebhookCacheOperation> .Ignored, A <ContentPageModel> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => FakeContentCacheService.Remove(A <Guid> .Ignored)).MustNotHaveHappened();

            Assert.Equal(expectedResponse, result);
        }