public async Task ApprenticeshipStandardsPatchTest(MessageAction messageAction) { var elementId = Guid.NewGuid(); //Arrange var patchApprenticeshipStandardsModel = new PatchApprenticeshipStandardsModel() { ActionType = messageAction, Id = elementId }; currentOpportunitiesSegmentModel.Data.Apprenticeships = new Apprenticeships() { Standards = new List <Data.Models.ApprenticeshipStandard>(), }; currentOpportunitiesSegmentModel.Data.Apprenticeships.Standards.Add(new Data.Models.ApprenticeshipStandard() { Id = elementId }); A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.OK); //Act var result = await CurrentOpportunitiesSegmentService.PatchApprenticeshipStandardsAsync(patchApprenticeshipStandardsModel, testGuid).ConfigureAwait(false); //Asserts A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).MustNotHaveHappened(); result.Should().Be(HttpStatusCode.OK); }
public async Task ApprenticeshipStandardsPatchStandardsNullTest() { //Arrange var patchApprenticeshipStandardsModel = new PatchApprenticeshipStandardsModel() { ActionType = MessageAction.Deleted }; A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).Returns(HttpStatusCode.AlreadyReported); //Act var result = await CurrentOpportunitiesSegmentService.PatchApprenticeshipStandardsAsync(patchApprenticeshipStandardsModel, testGuid).ConfigureAwait(false); //Asserts result.Should().Be(HttpStatusCode.AlreadyReported); }
public async Task <HttpStatusCode> PatchApprenticeshipStandardsAsync(PatchApprenticeshipStandardsModel patchModel, Guid documentId) { if (patchModel is null) { throw new ArgumentNullException(nameof(patchModel)); } var existingSegmentModel = await GetByIdAsync(documentId).ConfigureAwait(false); var currentOpportunitiesSegmentPatchStatus = currentOpportunitiesSegmentUtilities.IsSegementOkToPatch(existingSegmentModel, patchModel.SequenceNumber); if (!currentOpportunitiesSegmentPatchStatus.OkToPatch) { return(currentOpportunitiesSegmentPatchStatus.ReturnStatusCode); } if (existingSegmentModel.Data.Apprenticeships == null) { existingSegmentModel.Data.Apprenticeships = new Apprenticeships(); } if (existingSegmentModel.Data.Apprenticeships.Standards == null) { existingSegmentModel.Data.Apprenticeships.Standards = new List <Data.Models.ApprenticeshipStandard>(); } var existingApprenticeshipStandards = existingSegmentModel.Data?.Apprenticeships?.Standards?.FirstOrDefault(f => f.Id == patchModel.Id); if (existingApprenticeshipStandards is null) { return(currentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(patchModel.ActionType)); } if (patchModel.ActionType == MessageAction.Deleted) { existingSegmentModel.Data.Apprenticeships.Standards.Remove(existingApprenticeshipStandards); } else { mapper.Map(patchModel, existingApprenticeshipStandards); } existingSegmentModel.SequenceNumber = patchModel.SequenceNumber; return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false)); }
public async Task SegmentControllerPatchApprenticeshipStandardsReturnsBadRequestWhenNullPatchmodel(string mediaTypeName) { // Arrange const HttpStatusCode expectedResponse = HttpStatusCode.BadRequest; PatchApprenticeshipStandardsModel patchModel = null; var documentId = Guid.NewGuid(); var controller = BuildSegmentController(mediaTypeName); // Act var result = await controller.PatchApprenticeshipStandards(patchModel, documentId).ConfigureAwait(false); // Assert var statusResult = Assert.IsType <BadRequestResult>(result); Assert.Equal((int)expectedResponse, statusResult.StatusCode); controller.Dispose(); }
public async Task ApprenticeshipStandardsPatchStandardsReturnsNotFoundForMissingSegment() { //Arrange var doNotPatchResult = new CurrentOpportunitiesSegmentPatchStatus() { OkToPatch = false, ReturnStatusCode = HttpStatusCode.NotFound }; var patchApprenticeshipStandardsModel = new PatchApprenticeshipStandardsModel() { ActionType = MessageAction.Deleted }; A.CallTo(() => FakeRepository.GetAsync(A <Expression <Func <CurrentOpportunitiesSegmentModel, bool> > > .Ignored)).Returns(null as CurrentOpportunitiesSegmentModel); A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.IsSegementOkToPatch(A <CurrentOpportunitiesSegmentModel> .Ignored, A <long> .Ignored)).Returns(doNotPatchResult); //Act var result = await CurrentOpportunitiesSegmentService.PatchApprenticeshipStandardsAsync(patchApprenticeshipStandardsModel, testGuid).ConfigureAwait(false); //Asserts result.Should().Be(HttpStatusCode.NotFound); }
public async Task <IActionResult> PatchApprenticeshipStandards([FromBody] PatchApprenticeshipStandardsModel patchApprenticeshipStandardsModel, Guid documentId) { logService.LogInformation($"{nameof(PatchApprenticeshipStandards)} has been called"); if (patchApprenticeshipStandardsModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var response = await currentOpportunitiesSegmentService.PatchApprenticeshipStandardsAsync(patchApprenticeshipStandardsModel, documentId).ConfigureAwait(false); if (response != HttpStatusCode.OK && response != HttpStatusCode.Created) { logService.LogError($"{nameof(PatchApprenticeshipStandards)}: Error while patching Apprenticeship Standards content for Job Profile with Id: {patchApprenticeshipStandardsModel.JobProfileId} for the {patchApprenticeshipStandardsModel.SocCode} soc code"); } return(new StatusCodeResult((int)response)); }