Example #1
0
        public virtual ActionResult Create(ReviewCreateViewModel reviewCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                var writerId = _httpContextService.GetUserId();
                var writer = _writerRepository.GetById(writerId);

                //Todo: faire la map
                var review = new Review()
                {
                    WriterId = writer.Id,
                    RestaurantId = reviewCreateViewModel.RestaurantId,
                    Body = reviewCreateViewModel.Body,
                    Rating = reviewCreateViewModel.Rating
                };

                writer.Reviews.Add(review);
                _writerRepository.Update(writer);

                return RedirectToAction(MVC.Home.Index());
            }

            PopulateRestaurantSelectList(reviewCreateViewModel);
            return View(reviewCreateViewModel);
        }
        public void update_restaurant_by_adding_review_using_EFContext()
        {
            //Arrange
            int reviewsCountBefore;
            Restaurant restaurantToUpdate;
            int writerID;
            using (var context = new MiamDbContext())
            {
                restaurantToUpdate = context.Restaurants.First(r => r.Name == TestData.Restaurant1.Name);
                reviewsCountBefore = restaurantToUpdate.Reviews.Count();
                var writer = context.Writers.First();
                writerID = writer.Id;

            }
            var newReview = new Review()
                            {
                                Body = "Ambiance décontractée. Service trop familier.",
                                Rating = 3,
                                WriterId = writerID
                            };

            //Action
            using (var context = new MiamDbContext())
            {

                context.Restaurants.Attach(restaurantToUpdate);
                restaurantToUpdate.Reviews.Add(newReview);
                context.Entry(restaurantToUpdate).State = EntityState.Modified;
                context.SaveChanges();
            }

            //Assert
            using (var context = new MiamDbContext())
            {
                var restaurantAfter = context.Restaurants.First(r => r.Name == TestData.Restaurant1.Name);
                var reviewsCountAfter = restaurantAfter.Reviews.Count();
                Assert.AreEqual(reviewsCountBefore + 1, reviewsCountAfter);
            }
        }
Example #3
0
 private void ReviewRepositoryAddMethodShouldHaveReceived(Review review)
 {
     _reviewRepository.Received().Add(Arg.Is<Review>(x => x.WriterId == review.WriterId));
     _reviewRepository.Received().Add(Arg.Is<Review>(x => x.RestaurantId == review.RestaurantId));
     _reviewRepository.Received().Add(Arg.Is<Review>(x => x.Rating == review.Rating));
     _reviewRepository.Received().Add(Arg.Is<Review>(x => x.Body == review.Body));
 }
 private void ReviewRepositoryAddMethodShouldHaveReceived(Review review)
 {
     _writerRepository.Received().Update(Arg.Is<Writer>(x => x.Reviews.First().Body == review.Body));
     _writerRepository.Received().Update(Arg.Is<Writer>(x => x.Reviews.First().Writer == review.Writer));
     _writerRepository.Received().Update(Arg.Is<Writer>(x => x.Reviews.First().Restaurant == review.Restaurant));
 }
Example #5
0
 public void Add(Review review)
 {
     var dbContext = _dbContextFactory.Create();
     dbContext.Reviews.Add(review);
     dbContext.SaveChanges();
 }