public async Task <IActionResult> Post([FromBody] CareerPathSegmentModel careerPathSegmentModel)
        {
            logService.LogInformation($"{nameof(Post)} has been called");

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

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

            var existingDocument = await careerPathSegmentService.GetByIdAsync(careerPathSegmentModel.DocumentId).ConfigureAwait(false);

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

            var response = await careerPathSegmentService.UpsertAsync(careerPathSegmentModel).ConfigureAwait(false);

            logService.LogInformation($"{nameof(Post)} has created content for: {careerPathSegmentModel.CanonicalName}");

            return(new StatusCodeResult((int)response));
        }
Esempio n. 2
0
        public async Task CareerPathSegmentServiceCreateReturnsSuccessWhenSegmentCreated()
        {
            // arrange
            var careerPathSegmentModel = A.Fake <CareerPathSegmentModel>();

            A.CallTo(() => repository.UpsertAsync(A <CareerPathSegmentModel> .Ignored)).Returns(HttpStatusCode.Created);

            // act
            var result = await careerPathSegmentService.UpsertAsync(careerPathSegmentModel).ConfigureAwait(false);

            // assert
            A.CallTo(() => repository.UpsertAsync(A <CareerPathSegmentModel> .Ignored)).MustHaveHappenedOnceExactly();
            A.CallTo(() => jobProfileSegmentRefreshService.SendMessageAsync(A <RefreshJobProfileSegmentServiceBusModel> .Ignored)).MustHaveHappenedOnceExactly();
            Assert.Equal(HttpStatusCode.Created, result);
        }