public async Task JobProfileSocPatchDeleteApprentishipNullTest()
        {
            //Arrange
            var patchJobProfileSocModel = new PatchJobProfileSocModel()
            {
                ActionType = MessageAction.Deleted
            };

            A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).Returns(HttpStatusCode.AlreadyReported);

            //Act
            var result = await CurrentOpportunitiesSegmentService.PatchJobProfileSocAsync(patchJobProfileSocModel, testGuid).ConfigureAwait(false);

            //Asserts
            result.Should().Be(HttpStatusCode.AlreadyReported);
        }
示例#2
0
        public async Task SegmentControllerPatchJobProfileSocReturnsBadRequestWhenNullPatchmodel(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode    expectedResponse = HttpStatusCode.BadRequest;
            PatchJobProfileSocModel patchModel       = null;
            var documentId = Guid.NewGuid();
            var controller = BuildSegmentController(mediaTypeName);

            // Act
            var result = await controller.PatchJobProfileSoc(patchModel, documentId).ConfigureAwait(false);

            // Assert
            var statusResult = Assert.IsType <BadRequestResult>(result);

            Assert.Equal((int)expectedResponse, statusResult.StatusCode);

            controller.Dispose();
        }
        public async Task JobProfileSocPatchApprentishipTest(MessageAction messageAction)
        {
            //Arrange
            var patchJobProfileSocModel = new PatchJobProfileSocModel()
            {
                ActionType = messageAction
            };

            currentOpportunitiesSegmentModel.Data.Apprenticeships = new Apprenticeships();

            A.CallTo(() => FakeRepository.UpsertAsync(A <CurrentOpportunitiesSegmentModel> .Ignored)).Returns(HttpStatusCode.OK);

            //Act
            var result = await CurrentOpportunitiesSegmentService.PatchJobProfileSocAsync(patchJobProfileSocModel, testGuid).ConfigureAwait(false);

            //Asserts
            A.CallTo(() => FakeCurrentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(A <MessageAction> .Ignored)).MustNotHaveHappened();
            result.Should().Be(HttpStatusCode.OK);
        }
示例#4
0
        public async Task <HttpStatusCode> PatchJobProfileSocAsync(PatchJobProfileSocModel 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);
            }

            var existingApprenticeships = existingSegmentModel.Data.Apprenticeships;

            if (existingApprenticeships is null)
            {
                return(currentOpportunitiesSegmentUtilities.GetReturnStatusForNullElementPatchRequest(patchModel.ActionType));
            }

            if (patchModel.ActionType == MessageAction.Deleted)
            {
                existingSegmentModel.Data.Apprenticeships = new Apprenticeships();
            }
            else
            {
                var updatedApprenticeships = new Data.Models.Apprenticeships()
                {
                    Frameworks = mapper.Map <IList <Data.Models.ApprenticeshipFramework> >(patchModel.ApprenticeshipFramework),
                    Standards  = mapper.Map <IList <Data.Models.ApprenticeshipStandard> >(patchModel.ApprenticeshipStandards),
                    Vacancies  = new List <Data.Models.Vacancy>(),
                };

                existingSegmentModel.Data.Apprenticeships = updatedApprenticeships;
            }

            existingSegmentModel.SequenceNumber = patchModel.SequenceNumber;

            return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false));
        }
        public async Task JobProfileSocPatchSocReturnsNotFoundForMissingSegment()
        {
            //Arrange
            var doNotPatchResult = new CurrentOpportunitiesSegmentPatchStatus()
            {
                OkToPatch = false, ReturnStatusCode = HttpStatusCode.NotFound
            };
            var patchJobProfileSocModel = new PatchJobProfileSocModel()
            {
                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.PatchJobProfileSocAsync(patchJobProfileSocModel, testGuid).ConfigureAwait(false);

            //Asserts
            result.Should().Be(HttpStatusCode.NotFound);
        }
        public async Task <IActionResult> PatchJobProfileSoc([FromBody] PatchJobProfileSocModel patchJobProfileSocModel, Guid documentId)
        {
            logService.LogInformation($"{nameof(PatchJobProfileSoc)} has been called");

            if (patchJobProfileSocModel == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var response = await currentOpportunitiesSegmentService.PatchJobProfileSocAsync(patchJobProfileSocModel, documentId).ConfigureAwait(false);

            if (response != HttpStatusCode.OK && response != HttpStatusCode.Created)
            {
                logService.LogError($"{nameof(PatchJobProfileSoc)}: Error while patching Soc Data content for Job Profile with Id: {patchJobProfileSocModel.JobProfileId} for the {patchJobProfileSocModel.SocCode} soc code");
            }

            return(new StatusCodeResult((int)response));
        }