public async Task HowToBecomeSegmentServicePatchRegistrationReturnsExceptionWhenPatchmodelIsNull() { // arrange PatchRegistrationModel patchModel = null; var documentId = Guid.NewGuid(); // act var exceptionResult = await Assert.ThrowsAsync <ArgumentNullException>(async() => await howToBecomeSegmentService.PatchRegistrationAsync(patchModel, documentId).ConfigureAwait(false)).ConfigureAwait(false); // assert Assert.Equal("Value cannot be null. (Parameter 'patchModel')", exceptionResult.Message); }
public async Task SegmentControllerPatchRegistrationReturnsBadRequestWhenNullPatchmodel(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.BadRequest; PatchRegistrationModel patchModel = null; var documentId = Guid.NewGuid(); var controller = BuildSegmentController(mediaTypeName); // Act var result = await controller.PatchRegistration(patchModel, documentId).ConfigureAwait(false); // Assert var statusResult = Assert.IsType <BadRequestResult>(result); Assert.Equal((int)expectedResponse, statusResult.StatusCode); controller.Dispose(); }
public async Task <HttpStatusCode> PatchRegistrationAsync(PatchRegistrationModel 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 existingRegistration = existingSegmentModel.Data?.Registrations.FirstOrDefault(r => r.Id == patchModel.Id); if (existingRegistration is null) { return(patchModel.MessageAction == MessageAction.Deleted ? HttpStatusCode.AlreadyReported : HttpStatusCode.NotFound); } var existingIndex = existingSegmentModel.Data.Registrations.ToList().FindIndex(ai => ai.Id == patchModel.Id); if (patchModel.MessageAction == MessageAction.Deleted) { existingSegmentModel.Data.Registrations.RemoveAt(existingIndex); } else { var updatedRegistration = mapper.Map <Registration>(patchModel); existingSegmentModel.Data.Registrations[existingIndex] = updatedRegistration; } existingSegmentModel.SequenceNumber = patchModel.SequenceNumber; return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false)); }
public async Task <IActionResult> PatchRegistration([FromBody] PatchRegistrationModel patchRegistrationModel, Guid documentId) { logService.LogInformation($"{PatchSimpleClassificationActionName} has been called"); if (patchRegistrationModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = await howToBecomeSegmentService.PatchRegistrationAsync(patchRegistrationModel, documentId).ConfigureAwait(false); if (response != HttpStatusCode.OK && response != HttpStatusCode.Created) { logService.LogError($"{PatchRegistrationActionName}: Error while patching Registration content for Job Profile with Id: {patchRegistrationModel.JobProfileId} for the {patchRegistrationModel.RouteName.ToString()} link"); } return(new StatusCodeResult((int)response)); }