예제 #1
0
        public async Task <HttpStatusCode> PatchSimpleClassificationAsync(PatchSimpleClassificationModel 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);
            }

            var existingCommonRoute = existingSegmentModel.GetExistingCommonRoute(patchModel.RouteName);

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

            existingCommonRoute.EntryRequirementPreface = patchModel.MessageAction == MessageAction.Deleted ? string.Empty : patchModel.Title;

            existingSegmentModel.SequenceNumber = patchModel.SequenceNumber;
            return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false));
        }
예제 #2
0
        public async Task HowToBecomeSegmentServicePatchSimpleClassificationReturnsExceptionWhenPatchmodelIsNull()
        {
            // arrange
            PatchSimpleClassificationModel patchModel = null;
            var documentId = Guid.NewGuid();

            // act
            var exceptionResult = await Assert.ThrowsAsync <ArgumentNullException>(async() => await howToBecomeSegmentService.PatchSimpleClassificationAsync(patchModel, documentId).ConfigureAwait(false)).ConfigureAwait(false);

            // assert
            Assert.Equal("Value cannot be null. (Parameter 'patchModel')", exceptionResult.Message);
        }
예제 #3
0
        public async Task SegmentControllerPatchEntryRequirementReturnsBadRequestWhenNullPatchmodel(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode           expectedResponse = HttpStatusCode.BadRequest;
            PatchSimpleClassificationModel patchModel       = null;
            var documentId = Guid.NewGuid();
            var controller = BuildSegmentController(mediaTypeName);

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

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

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

            controller.Dispose();
        }
        public async Task <IActionResult> PatchEntryRequirement([FromBody] PatchSimpleClassificationModel patchSimpleClassificationModel, Guid documentId)
        {
            logService.LogInformation($"{PatchSimpleClassificationActionName} has been called");

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

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

            var response = await howToBecomeSegmentService.PatchSimpleClassificationAsync(patchSimpleClassificationModel, documentId).ConfigureAwait(false);

            if (response != HttpStatusCode.OK && response != HttpStatusCode.Created)
            {
                logService.LogError($"{PatchSimpleClassificationActionName}: Error while patching Entry Requirement content for Job Profile with Id: {patchSimpleClassificationModel.JobProfileId} for the {patchSimpleClassificationModel.RouteName.ToString()} link");
            }

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