public async Task <IActionResult> AddReview([FromBody] ReviewDTO newReview) { Task validateThenAdd() { _payloadValidator.ValidateData(newReview); return(_reviewRepository.AddReview(newReview)); } return(await toHttpResponse(() => validateThenAdd(), _logger)); }
public IActionResult PostReview(Review review) { if (ReviewExists(review.UserId, review.RecipeId)) { _logger.LogWarning($"Review with user id: {review.UserId} and recipe id: {review.RecipeId} already exists."); return(Conflict()); } _reviewRepo.AddReview(review); _reviewRepo.SaveChanges(); _logger.LogInformation($"Review with user id: {review.UserId} and recipe id: {review.RecipeId} has been added."); return(CreatedAtAction(nameof(GetReview), review)); }
public ActionResult <ReviewAddReturnDTO> AddReview(Review review) { try { var result = _reviewRepo.AddReview(review); return(Ok(result)); } catch (Exception e) { // TODO log e Console.WriteLine(e); return(new BadRequestResult()); } }
public void TestGetReviewsByBook() { //Arrange repo = new FakeReviewRepo(); SeedReviewData(); foreach (Review r in reviews) { repo.AddReview(r); } //Act IEnumerable <Review> Pj = repo.GetReviewsByBook(books[0]); //Assert Assert.Equal(2, Pj.Count()); Assert.Equal("Stiles", Pj.ElementAt(1).Reviewer); Assert.Equal("The Lightning Thief", Pj.ElementAt(1).BookTitle); }
public void TestGetReviewById() { //Arrange repo = new FakeReviewRepo(); SeedReviewData(); foreach (Review r in reviews) { repo.AddReview(r); } //Act Review stilesHP = repo.GetReviewById(2); //Assert Assert.Equal("Harry Potter and the Sorceror's Stone", stilesHP.BookTitle); Assert.Equal("Stiles", stilesHP.Reviewer); Assert.NotEqual("TeenWolf", stilesHP.Reviewer); }
public void TestAddReview() { //Arrange repo = new FakeReviewRepo(); SeedData(); Review review = new Review() { Reviewer = users[0].UserName, BookTitle = books[0].Title, BookRating = 5, ReviewID = 0, Text = "This book was really good! I can't believe I hadn't read it before!" }; //Act repo.AddReview(review); //Assert Assert.Single(repo.Reviews); Assert.Equal("TeenWolf", repo.Reviews.ElementAt(0).Reviewer); Assert.Equal("The Lightning Thief", repo.Reviews.ElementAt(0).BookTitle); }