public ActionResult <ReviewOutputDto> Post(long bookId, [FromBody] ReviewInputDto reviewDto) { var review = _mapper.Map <ReviewInputDto, Review>(reviewDto); review.User = new User { Id = reviewDto.UserId }; review.Book = new Book { Id = bookId }; var insertedReview = _reviewsRepository.Insert(review); var insertedReviewDto = _mapper.Map <ReviewOutputDto>(insertedReview); return(StatusCode(201, insertedReviewDto)); }
public void Map_Review_Input() { //Arrange var sut = _mapperConfiguration.CreateMapper(); var reviewInputDto = new ReviewInputDto { UserId = 2, Comment = "Nice!", Rate = 10 }; //Act var review = sut.Map <Review>(reviewInputDto); //Assert Assert.That(review.User.Id, Is.EqualTo(reviewInputDto.UserId)); Assert.That(review.Comment, Is.EqualTo(reviewInputDto.Comment)); Assert.That(review.Rate, Is.EqualTo(reviewInputDto.Rate)); }