public async Task <IActionResult> Post([FromBody] JobProfileOverviewSegmentModel jobProfileOverviewSegmentModel) { logService.LogInformation($"{PostActionName} has been called"); if (jobProfileOverviewSegmentModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingDocument = await jobProfileOverviewSegmentService.GetByIdAsync(jobProfileOverviewSegmentModel.DocumentId).ConfigureAwait(false); if (existingDocument != null) { return(new StatusCodeResult((int)HttpStatusCode.AlreadyReported)); } var response = await jobProfileOverviewSegmentService.UpsertAsync(jobProfileOverviewSegmentModel).ConfigureAwait(false); logService.LogInformation($"{PostActionName} has upserted content for: {jobProfileOverviewSegmentModel.CanonicalName}"); return(new StatusCodeResult((int)response)); }
public async Task JobProfileOverviewSegmentServiceUpsertReturnsCreatedWhenDocumentCreated() { // arrange var jobProfileOverviewSegmentModel = A.Fake <JobProfileOverviewSegmentModel>(); var expectedResult = HttpStatusCode.Created; A.CallTo(() => repository.UpsertAsync(jobProfileOverviewSegmentModel)).Returns(expectedResult); // act var result = await jobProfileOverviewSegmentService.UpsertAsync(jobProfileOverviewSegmentModel).ConfigureAwait(false); // assert A.CallTo(() => repository.UpsertAsync(jobProfileOverviewSegmentModel)).MustHaveHappenedOnceExactly(); Assert.Equal(expectedResult, result); }