Ejemplo n.º 1
0
        public async Task JobProfileOverviewSegmentServicePatchWorkingHoursDetailReturnsExceptionWhenPatchmodelIsNull()
        {
            // arrange
            PatchWorkingHoursDetailModel patchModel = null;
            var documentId = Guid.NewGuid();

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

            // assert
            Assert.Equal("Value cannot be null. (Parameter 'patchModel')", exceptionResult.Message);
        }
Ejemplo n.º 2
0
        public async Task SegmentControllerPatchWorkingHoursDetailReturnsBadRequestWhenNullPatchmodel(string mediaTypeName)
        {
            // Arrange
            const HttpStatusCode         expectedResponse = HttpStatusCode.BadRequest;
            PatchWorkingHoursDetailModel patchModel       = null;
            var documentId = Guid.NewGuid();
            var controller = BuildSegmentController(mediaTypeName);

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

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

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

            controller.Dispose();
        }
        public async Task <HttpStatusCode> PatchWorkingHoursDetailAsync(PatchWorkingHoursDetailModel 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 existingWorkingHoursDetail = existingSegmentModel.Data?.WorkingHoursDetails.SingleOrDefault(r => r.Id == patchModel.Id);

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

            var existingIndex = existingSegmentModel.Data.WorkingHoursDetails.ToList().FindIndex(ai => ai.Id == patchModel.Id);

            if (patchModel.MessageAction == MessageAction.Deleted)
            {
                existingSegmentModel.Data.WorkingHoursDetails.RemoveAt(existingIndex);
            }
            else
            {
                var updatedWorkingHoursDetail = mapper.Map <Data.Models.WorkingHoursDetail>(patchModel);
                existingSegmentModel.Data.WorkingHoursDetails[existingIndex] = updatedWorkingHoursDetail;
            }

            existingSegmentModel.SequenceNumber = patchModel.SequenceNumber;

            return(await UpsertAndRefreshSegmentModel(existingSegmentModel).ConfigureAwait(false));
        }
        public async Task <IActionResult> PatchWorkingHoursDetail([FromBody] PatchWorkingHoursDetailModel patchWorkingHoursDetailModel, Guid documentId)
        {
            logService.LogInformation($"{PatchWorkingHoursDetailActionName} has been called");

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

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

            var response = await jobProfileOverviewSegmentService.PatchWorkingHoursDetailAsync(patchWorkingHoursDetailModel, documentId).ConfigureAwait(false);

            if (response != HttpStatusCode.OK && response != HttpStatusCode.Created)
            {
                logService.LogError($"{PatchWorkingHoursDetailActionName}: Error while patching Working Hours Detail content for Job Profile with Id: {patchWorkingHoursDetailModel.JobProfileId} for the {patchWorkingHoursDetailModel.Title} hours detail");
            }

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