public async Task <IActionResult> Create([FromBody] ContentPageModel upsertContentPageModel) { logger.LogInformation($"{nameof(Create)} has been called"); if (upsertContentPageModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingDocument = await contentPageService.GetByIdAsync(upsertContentPageModel.DocumentId).ConfigureAwait(false); if (existingDocument != null) { return(new StatusCodeResult((int)HttpStatusCode.AlreadyReported)); } var response = await contentPageService.UpsertAsync(upsertContentPageModel).ConfigureAwait(false); logger.LogInformation($"{nameof(Create)} has upserted content for: {upsertContentPageModel.Category}/{upsertContentPageModel.CanonicalName} with response code {response}"); return(new StatusCodeResult((int)response)); }
public async Task <HttpStatusCode> CreateAsync(TModel?upsertDocumentModel) { if (upsertDocumentModel == null) { return(HttpStatusCode.BadRequest); } var existingDocument = await contentPageService.GetByIdAsync(upsertDocumentModel.Id).ConfigureAwait(false); if (existingDocument != null) { return(HttpStatusCode.AlreadyReported); } upsertDocumentModel.PageLocation = ExtractPageLocation(upsertDocumentModel); var response = await contentPageService.UpsertAsync(upsertDocumentModel).ConfigureAwait(false); logger.LogInformation($"{nameof(CreateAsync)} has upserted content for: {upsertDocumentModel.CanonicalName} with response code {response}"); return(response); }
public async Task <HttpStatusCode> CreateAsync(TModel?upsertDocumentModel) { if (upsertDocumentModel == null) { return(HttpStatusCode.BadRequest); } var existingDocument = await contentPageService.GetByIdAsync(upsertDocumentModel.Id).ConfigureAwait(false); if (existingDocument != null) { return(HttpStatusCode.AlreadyReported); } var beforePageLocationUpdate = JsonConvert.SerializeObject(upsertDocumentModel); upsertDocumentModel.PageLocation = ExtractPageLocation(upsertDocumentModel); if (string.IsNullOrEmpty(upsertDocumentModel.PageLocation)) { logger.LogError( "PageLocation ({PageLocation}) and/or PartitionKey ({PartitionKey}) is empty or null. Document before = {SerialisedDocumentBefore}. Document = {SerialisedDocument}", upsertDocumentModel.PageLocation, upsertDocumentModel.PartitionKey, beforePageLocationUpdate, JsonConvert.SerializeObject(upsertDocumentModel)); return(HttpStatusCode.BadRequest); } var response = await contentPageService.UpsertAsync(upsertDocumentModel).ConfigureAwait(false); logger.LogInformation($"{nameof(CreateAsync)} has upserted content for: {upsertDocumentModel.CanonicalName} with response code {response}"); return(response); }
public async Task EventMessageServiceCreateAsyncReturnsSuccess() { // arrange ContentPageModel?existingContentPageModel = null; var contentPageModel = A.Fake <ContentPageModel>(); contentPageModel.PageLocations = new List <PageLocationModel> { new PageLocationModel(), }; var expectedResult = HttpStatusCode.OK; A.CallTo(() => fakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).Returns(existingContentPageModel); A.CallTo(() => fakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).Returns(expectedResult); var eventMessageService = new EventMessageService <ContentPageModel>(fakeLogger, fakeContentPageService); // act var result = await eventMessageService.CreateAsync(contentPageModel).ConfigureAwait(false); // assert A.CallTo(() => fakeContentPageService.GetByIdAsync(A <Guid> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => fakeContentPageService.UpsertAsync(A <ContentPageModel> .Ignored)).MustHaveHappenedOnceExactly(); A.Equals(result, expectedResult); }