Exemple #1
0
        public async Task AddReviews_VerifyIfAReviewIsAddedToARestaurant()
        {
            ReviewsAC ReviewsAC = new ReviewsAC
            {
                ReviewId    = 1,
                ReviewTexts = "Good",
                LikesCount  = 4,
                userID      = "dcbe1262-4be8-493a-8821-f4d52778d878",
                UserName    = "******",
                commentACs  = new List <CommentAC>
                {
                    new CommentAC
                    {
                        ID             = 1,
                        ReviewID       = 1,
                        UserID         = "dcbe1262-4be8-493a-8821-f4d52778d878",
                        FullName       = "Nina Dobrev",
                        CommentMessage = "Okay"
                    }
                }
            };

            List <Restaurant> restaurants = new List <Restaurant>
            {
                new Restaurant
                {
                    ID = 1
                }
            };
            List <User> users = new List <User>
            {
                new User
                {
                    Id       = "dcbe1262-4be8-493a-8821-f4d52778d878",
                    UserName = "******"
                }
            };


            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <Restaurant, bool> > >())).Returns(restaurants.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <User, bool> > >())).Returns(users.AsQueryable().BuildMock().Object);
            //_dataRepository.Setup(s => s.AddAsync(It.IsAny<Expression<Func<Likes, bool>>>()));
            //_dataRepository.Setup(s => s.SaveChangesAsync());

            await _unitOfWorkRepository.Restaurant.AddReviews(1, ReviewsAC);

            _dataRepository.Verify(v => v.AddAsync(It.IsAny <Review>()), Times.Once);
            _dataRepository.Verify(v => v.SaveChangesAsync());
        }
        //post reviews
        public async Task <ReviewsAC> AddReviews(int restaurantId, ReviewsAC reviews)
        {
            Review review = new Review();

            _mapper.Map(reviews, review);
            review.Restaurant = await _dataRepository.Where <Restaurant>(r => r.ID == restaurantId).FirstAsync();

            review.User = await _dataRepository.Where <User>(u => u.Id == reviews.userID).FirstAsync();

            await _dataRepository.AddAsync <Review>(review);

            await _dataRepository.SaveChangesAsync();

            return(_mapper.Map(review, reviews));
        }
        //post for likes
        public async Task <ReviewsAC> Likes(int reviewId, string userId)
        {
            var review = await _dataRepository.Where <Review>(k => k.ID == reviewId).Include(k => k.User).FirstOrDefaultAsync();

            var user = await _dataRepository.Where <User>(k => k.Id == userId).FirstOrDefaultAsync();

            var likes = new Likes();

            likes.Reviews      = review;
            likes.Users        = user;
            review.LikesCount += 1;
            await _dataRepository.AddAsync(likes);

            ReviewsAC reviews = new ReviewsAC();

            _mapper.Map(review, reviews);

            await _dataRepository.SaveChangesAsync();

            return(reviews);
        }
        public async Task <ActionResult> AddReviews([FromRoute] int restaurantId, [FromBody] ReviewsAC reviews)
        {
            var r = await unitOfWork.Restaurant.AddReviews(restaurantId, reviews);

            return(Ok(r));
        }
        public async Task <IActionResult> Likes(ReviewsAC review)
        {
            var x = await unitOfWork.Restaurant.Likes(review.ReviewId, review.userID);

            return(Ok(x));
        }
Exemple #6
0
        public async Task Likes_VerifyWhetherAReviewPostIsGettingLikedOrNot()
        {
            List <Restaurant> restaurants = new List <Restaurant>
            {
                new Restaurant
                {
                    ID             = 1,
                    RestaurantName = "Domino's",
                    CuisineType    = "Italian",
                    Dishes         = new List <Dishes>
                    {
                        new Dishes
                        {
                            ID         = 1,
                            DishesName = "Pizza",
                            Costs      = 250
                        },
                        new Dishes
                        {
                            ID         = 2,
                            DishesName = "Taco",
                            Costs      = 150
                        }
                    }
                }
            };

            List <User> users = new List <User>
            {
                new User
                {
                    Id       = "dcbe1262-4be8-493a-8821-f4d52778d878",
                    FullName = "Nina Dobrev"
                }
            };

            ReviewsAC ReviewsAC = new ReviewsAC
            {
                ReviewId    = 1,
                ReviewTexts = "Good",
                userID      = "dcbe1262-4be8-493a-8821-f4d52778d878",
                LikesCount  = 4,
                UserName    = "******",
                commentACs  = new List <CommentAC>
                {
                    new CommentAC
                    {
                        ID             = 1,
                        ReviewID       = 1,
                        UserID         = "dcbe1262-4be8-493a-8821-f4d52778d878",
                        FullName       = "Nina Dobrev",
                        CommentMessage = "Okay"
                    }
                }
            };

            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <Restaurant, bool> > >())).Returns(restaurants.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.Where(It.IsAny <Expression <Func <User, bool> > >())).Returns(users.AsQueryable().BuildMock().Object);
            _dataRepository.Setup(s => s.AddAsync(It.IsAny <Expression <Func <Review, bool> > >()));
            _dataRepository.Setup(s => s.SaveChangesAsync());

            await _unitOfWorkRepository.Restaurant.Likes(1, "");

            //_dataRepository.Verify(v => v.AddAsync(It.IsAny<Review>()), Times.Once);
            _dataRepository.Verify(v => v.SaveChangesAsync());
        }