public async Task <IActionResult> Post([FromBody] JobProfileSkillSegmentModel jobProfileSkillSegmentModel)
        {
            logService.LogInformation($"{PostActionName} has been called");

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

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

            var existingDocument = await skillSegmentService.GetByIdAsync(jobProfileSkillSegmentModel.DocumentId).ConfigureAwait(false);

            if (existingDocument != null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.AlreadyReported));
            }

            var response = await skillSegmentService.UpsertAsync(jobProfileSkillSegmentModel).ConfigureAwait(false);

            logService.LogInformation($"{PostActionName} has upserted content for: {jobProfileSkillSegmentModel.CanonicalName}");

            return(new StatusCodeResult((int)response));
        }
コード例 #2
0
        public async Task UpsertReturnsCreatedWhenDocumentCreated()
        {
            // Arrange
            var skillSegmentModel = A.Fake <JobProfileSkillSegmentModel>();
            var expectedResult    = HttpStatusCode.Created;

            A.CallTo(() => repository.UpsertAsync(skillSegmentModel)).Returns(expectedResult);

            // Act
            var result = await skillSegmentService.UpsertAsync(skillSegmentModel).ConfigureAwait(false);

            // Assert
            A.CallTo(() => repository.UpsertAsync(skillSegmentModel)).MustHaveHappenedOnceExactly();
            Assert.Equal(expectedResult, result);
        }