コード例 #1
0
        public async Task SegmentControllerPatchDigitalSkillReturnsBadRequestWhenModelIsInvalid()
        {
            // Arrange
            var model      = new PatchDigitalSkillModel();
            var controller = BuildSegmentController();

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

            // Act
            var result = await controller.PatchDigitalSkill(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 SegmentControllerPatchDigitalSkillReturnsSuccessForSuccessfulResponse(HttpStatusCode expectedStatus)
        {
            // Arrange
            var controller = BuildSegmentController();
            var model      = new PatchDigitalSkillModel();

            A.CallTo(() => FakeSkillSegmentService.PatchDigitalSkillAsync(A <PatchDigitalSkillModel> .Ignored, A <Guid> .Ignored)).Returns(expectedStatus);

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

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

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

            controller.Dispose();
        }
        public async Task <IActionResult> PatchDigitalSkill([FromBody] PatchDigitalSkillModel patchDigitalSkillModel, Guid documentId)
        {
            logService.LogInformation($"{PatchDigitalSkillActionName} has been called");

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

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

            var response = await skillSegmentService.PatchDigitalSkillAsync(patchDigitalSkillModel, documentId).ConfigureAwait(false);

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

            return(new StatusCodeResult((int)response));
        }
コード例 #4
0
        public async Task <HttpStatusCode> PatchDigitalSkillAsync(PatchDigitalSkillModel patchModel, Guid documentId)
        {
            if (patchModel == null)
            {
                throw new ArgumentNullException(nameof(patchModel));
            }

            var existingSegmentModel = await GetByIdAsync(documentId).ConfigureAwait(false);

            if (existingSegmentModel == null)
            {
                return(HttpStatusCode.NotFound);
            }

            if (patchModel.SequenceNumber <= existingSegmentModel.SequenceNumber)
            {
                return(HttpStatusCode.AlreadyReported);
            }

            existingSegmentModel.Data.DigitalSkill = patchModel.MessageAction == MessageAction.Deleted ? string.Empty : patchModel.Title;
            existingSegmentModel.SequenceNumber    = patchModel.SequenceNumber;

            return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false));
        }