public async Task JobProfileOverviewSegmentServicePatchWorkingPatternDetailReturnsExceptionWhenPatchmodelIsNull() { // arrange PatchWorkingPatternDetailModel patchModel = null; var documentId = Guid.NewGuid(); // act var exceptionResult = await Assert.ThrowsAsync <ArgumentNullException>(async() => await jobProfileOverviewSegmentService.PatchWorkingPatternDetailAsync(patchModel, documentId).ConfigureAwait(false)).ConfigureAwait(false); // assert Assert.Equal("Value cannot be null. (Parameter 'patchModel')", exceptionResult.Message); }
public async Task SegmentControllerPatchWorkingPatternDetailReturnsBadRequestWhenNullPatchmodel(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.BadRequest; PatchWorkingPatternDetailModel patchModel = null; var documentId = Guid.NewGuid(); var controller = BuildSegmentController(mediaTypeName); // Act var result = await controller.PatchWorkingPatternDetail(patchModel, documentId).ConfigureAwait(false); // Assert var statusResult = Assert.IsType <BadRequestResult>(result); Assert.Equal((int)expectedResponse, statusResult.StatusCode); controller.Dispose(); }
public async Task <HttpStatusCode> PatchWorkingPatternDetailAsync(PatchWorkingPatternDetailModel patchModel, Guid documentId) { if (patchModel is null) { throw new ArgumentNullException(nameof(patchModel)); } var existingSegmentModel = await GetByIdAsync(documentId).ConfigureAwait(false); if (existingSegmentModel is null) { return(HttpStatusCode.NotFound); } if (patchModel.SequenceNumber <= existingSegmentModel.SequenceNumber) { return(HttpStatusCode.AlreadyReported); } var existingWorkingPatternDetail = existingSegmentModel.Data?.WorkingPatternDetails.SingleOrDefault(r => r.Id == patchModel.Id); if (existingWorkingPatternDetail is null) { return(patchModel.MessageAction == MessageAction.Deleted ? HttpStatusCode.AlreadyReported : HttpStatusCode.NotFound); } var existingIndex = existingSegmentModel.Data.WorkingPatternDetails.ToList().FindIndex(ai => ai.Id == patchModel.Id); if (patchModel.MessageAction == MessageAction.Deleted) { existingSegmentModel.Data.WorkingPatternDetails.RemoveAt(existingIndex); } else { var updatedWorkingPatternDetail = mapper.Map <Data.Models.WorkingPatternDetail>(patchModel); existingSegmentModel.Data.WorkingPatternDetails[existingIndex] = updatedWorkingPatternDetail; } existingSegmentModel.SequenceNumber = patchModel.SequenceNumber; return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false)); }
public async Task <IActionResult> PatchWorkingPatternDetail([FromBody] PatchWorkingPatternDetailModel patchWorkingPatternDetailModel, Guid documentId) { logService.LogInformation($"{PatchWorkingPatternDetailActionName} has been called"); if (patchWorkingPatternDetailModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = await jobProfileOverviewSegmentService.PatchWorkingPatternDetailAsync(patchWorkingPatternDetailModel, documentId).ConfigureAwait(false); if (response != HttpStatusCode.OK && response != HttpStatusCode.Created) { logService.LogError($"{PatchWorkingPatternDetailActionName}: Error while patching Working Pattern Detail content for Job Profile with Id: {patchWorkingPatternDetailModel.JobProfileId} for the {patchWorkingPatternDetailModel.Title} pattern detail"); } return(new StatusCodeResult((int)response)); }