Пример #1
0
        public async Task SegmentControllerPatchOnetSkillReturnsBadRequestWhenModelIsInvalid()
        {
            // Arrange
            var model      = new PatchOnetSkillModel();
            var controller = BuildSegmentController();

            controller.ModelState.AddModelError(string.Empty, "Model is not valid");

            // Act
            var result = await controller.PatchOnetSkill(model, Guid.NewGuid()).ConfigureAwait(false);

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

            Assert.Equal((int)HttpStatusCode.BadRequest, statusResult.StatusCode);

            controller.Dispose();
        }
Пример #2
0
        public async Task SegmentControllerPatchOnetSkillReturnsSuccessForSuccessfulResponse(HttpStatusCode expectedStatus)
        {
            // Arrange
            var controller = BuildSegmentController();
            var model      = new PatchOnetSkillModel();

            A.CallTo(() => FakeSkillSegmentService.PatchOnetSkillAsync(A <PatchOnetSkillModel> .Ignored, A <Guid> .Ignored)).Returns(expectedStatus);

            // Act
            var result = await controller.PatchOnetSkill(model, Guid.NewGuid()).ConfigureAwait(false);

            // Assert
            A.CallTo(() => FakeSkillSegmentService.PatchOnetSkillAsync(A <PatchOnetSkillModel> .Ignored, A <Guid> .Ignored)).MustHaveHappenedOnceExactly();
            var statusCodeResult = Assert.IsType <StatusCodeResult>(result);

            Assert.Equal((int)expectedStatus, statusCodeResult.StatusCode);

            controller.Dispose();
        }
Пример #3
0
        public async Task <HttpStatusCode> PatchOnetSkillAsync(PatchOnetSkillModel 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 existingSkillMatrix = existingSegmentModel.Data?.Skills?.FirstOrDefault(s => s.OnetSkill?.Id == patchModel.Id);

            if (existingSkillMatrix is null)
            {
                return(patchModel.MessageAction == MessageAction.Deleted ? HttpStatusCode.AlreadyReported : HttpStatusCode.NotFound);
            }

            if (patchModel.MessageAction == MessageAction.Deleted)
            {
                existingSkillMatrix.OnetSkill = null;
            }
            else
            {
                existingSkillMatrix.OnetSkill = mapper.Map <OnetSkill>(patchModel);
            }

            existingSegmentModel.SequenceNumber = patchModel.SequenceNumber;

            return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false));
        }
        public async Task <IActionResult> PatchOnetSkill([FromBody] PatchOnetSkillModel patchOnetSkillModel, Guid documentId)
        {
            logService.LogInformation($"{PatchOnetSkillActionName} has been called");

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

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

            var response = await skillSegmentService.PatchOnetSkillAsync(patchOnetSkillModel, documentId).ConfigureAwait(false);

            if (response != HttpStatusCode.OK && response != HttpStatusCode.Created)
            {
                logService.LogError($"{PatchOnetSkillActionName}: Error while patching Related Skill content for Job Profile with Id: {patchOnetSkillModel.JobProfileId} for {patchOnetSkillModel.Title} ");
            }

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