public async Task <HttpStatusCode> PutAsync(CareerPathSegmentModel careerPathSegmentModel) { var url = new Uri($"{segmentClientOptions?.BaseAddress}segment"); using (var content = new ObjectContent(typeof(CareerPathSegmentModel), careerPathSegmentModel, new JsonMediaTypeFormatter(), MediaTypeNames.Application.Json)) { ConfigureHttpClient(); var response = await httpClient.PutAsync(url, content).ConfigureAwait(false); if (!response.IsSuccessStatusCode && response.StatusCode != HttpStatusCode.NotFound) { var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); logger.LogError($"Failure status code '{response.StatusCode}' received with content '{responseContent}', for Put type {typeof(CareerPathSegmentModel)}, Id: {careerPathSegmentModel?.DocumentId}"); response.EnsureSuccessStatusCode(); } return(response.StatusCode); } }
public async Task <HttpStatusCode> UpsertAsync(CareerPathSegmentModel careerPathSegmentModel) { if (careerPathSegmentModel == null) { throw new ArgumentNullException(nameof(careerPathSegmentModel)); } if (careerPathSegmentModel.Data == null) { careerPathSegmentModel.Data = new CareerPathSegmentDataModel(); } var result = await repository.UpsertAsync(careerPathSegmentModel).ConfigureAwait(false); if (result == HttpStatusCode.OK || result == HttpStatusCode.Created) { var refreshJobProfileSegmentServiceBusModel = mapper.Map <RefreshJobProfileSegmentServiceBusModel>(careerPathSegmentModel); await jobProfileSegmentRefreshService.SendMessageAsync(refreshJobProfileSegmentServiceBusModel).ConfigureAwait(false); } return(result); }
public async Task SegmentControllerDocumentHtmlReturnsNoContentWhenNoData(string mediaTypeName) { // Arrange CareerPathSegmentModel expectedResult = null; var controller = BuildSegmentController(mediaTypeName); A.CallTo(() => FakeCareerPathSegmentService.GetByNameAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await controller.Document(Article).ConfigureAwait(false); // Assert A.CallTo(() => FakeCareerPathSegmentService.GetByNameAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <DocumentViewModel>(A <CareerPathSegmentModel> .Ignored)).MustNotHaveHappened(); var statusResult = Assert.IsType <NoContentResult>(result); Assert.Equal((int)HttpStatusCode.NoContent, statusResult.StatusCode); controller.Dispose(); }
public async Task <IActionResult> Put([FromBody] CareerPathSegmentModel careerPathSegmentModel) { logService.LogInformation($"{nameof(Put)} has been called"); if (careerPathSegmentModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingDocument = await careerPathSegmentService.GetByIdAsync(careerPathSegmentModel.DocumentId).ConfigureAwait(false); if (existingDocument == null) { logService.LogInformation($"{nameof(Put)}. Couldnt find document with Id {careerPathSegmentModel.DocumentId}"); return(new StatusCodeResult((int)HttpStatusCode.NotFound)); } if (careerPathSegmentModel.SequenceNumber <= existingDocument.SequenceNumber) { return(new StatusCodeResult((int)HttpStatusCode.AlreadyReported)); } careerPathSegmentModel.Etag = existingDocument.Etag; careerPathSegmentModel.SocLevelTwo = existingDocument.SocLevelTwo; var response = await careerPathSegmentService.UpsertAsync(careerPathSegmentModel).ConfigureAwait(false); logService.LogInformation($"{nameof(Put)} has updated content for: {careerPathSegmentModel.CanonicalName}"); return(new StatusCodeResult((int)response)); }