public void ReturnCorrectReviews_When_ParamsValid()
        {
            var options = Utils.GetOptions(nameof(ReturnCorrectReviews_When_ParamsValid));

            var review  = TestsModelsSeeder.SeedReview();
            var review2 = TestsModelsSeeder.SeedReview2();
            var review3 = TestsModelsSeeder.SeedReview3();
            var beer    = TestsModelsSeeder.SeedBeer();
            var beer2   = TestsModelsSeeder.SeedBeer2();
            var beer3   = TestsModelsSeeder.SeedBeer3();
            var user    = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Reviews.Add(review);
                arrangeContext.Reviews.Add(review2);
                arrangeContext.Reviews.Add(review3);
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(beer);
                arrangeContext.Beers.Add(beer2);
                arrangeContext.Beers.Add(beer3);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new ReviewServices(assertContext);
                var result = sut.GetAllReviews().ToList();
                Assert.AreEqual(3, result.Count());
                Assert.AreEqual(review.Name, result[0].Name);
                Assert.AreEqual(review2.Name, result[1].Name);
                Assert.AreEqual(review3.Name, result[2].Name);
            }
        }
Ejemplo n.º 2
0
        public void CreateCurrectReview_When_ParamsValid()
        {
            var options    = Utils.GetOptions(nameof(CreateCurrectReview_When_ParamsValid));
            var reviewDTO  = TestsModelsSeeder.SeedReviewDTO();
            var user       = TestsModelsSeeder.SeedUser();
            var targetbeer = TestsModelsSeeder.SeedBeer();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(targetbeer);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new ReviewServices(assertContext);
                var act = sut.CreateReview(reviewDTO);
                assertContext.SaveChanges();
                var result = assertContext.Reviews.ToList()[0];
                Assert.AreEqual(reviewDTO.Name, result.Name);
                Assert.AreEqual(reviewDTO.Rating, result.Rating);
                Assert.AreEqual(reviewDTO.Text, result.Text);
                Assert.AreEqual(reviewDTO.Author, reviewDTO.Author);
            }
        }
        public void ReturnCorrectList_WhenDataIsPresent()
        {
            var options  = Utils.GetOptions(nameof(ReturnCorrectList_WhenDataIsPresent));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var user1    = TestsModelsSeeder.SeedUser();
            var user2    = TestsModelsSeeder.SeedUser2();
            var user3    = TestsModelsSeeder.SeedUser3();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user1);
                arrangeContext.Users.Add(user2);
                arrangeContext.Users.Add(user3);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var result = sut.GetAllUsers().ToList();
                Assert.AreEqual(3, result.Count);
                Assert.AreEqual(user1.UserName, result[0].UserName);
                Assert.AreEqual(user2.UserName, result[1].UserName);
                Assert.AreEqual(user3.UserName, result[2].UserName);
            }
        }
Ejemplo n.º 4
0
        public void ReturnCorrectReview_When_ParamsValid()
        {
            var options = Utils.GetOptions(nameof(ReturnCorrectReview_When_ParamsValid));
            var review  = TestsModelsSeeder.SeedReview();
            var beer    = TestsModelsSeeder.SeedBeer();
            var user    = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Add(review);
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(beer);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new ReviewServices(assertContext);
                var result = sut.GetReview(1);
                Assert.AreEqual(review.Name, result.Name);
                Assert.AreEqual(review.Author.UserName, result.Author);
                Assert.AreEqual(review.Text, result.Text);
                Assert.AreEqual(review.Rating, result.Rating);
            }
        }
Ejemplo n.º 5
0
        public void ThrowArgumentException_When_TargetBeerNotValid()
        {
            var options   = Utils.GetOptions(nameof(ThrowArgumentException_When_TargetBeerNotValid));
            var user      = TestsModelsSeeder.SeedUser();
            var reviewDTO = TestsModelsSeeder.SeedReviewDTO();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new ReviewServices(assertContext);
                Assert.ThrowsException <ArgumentNullException>(() => sut.CreateReview(reviewDTO));
            }
        }
        public void Throw_WhenBeersDrankBeerIdIsInvalid()
        {
            var options = Utils.GetOptions(nameof(Throw_WhenBeersDrankBeerIdIsInvalid));
            var user    = TestsModelsSeeder.SeedUser();
            var beer    = TestsModelsSeeder.SeedBeer();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(beer);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new UserServices(assertContext);
                Assert.ThrowsException <ArgumentNullException>(() => sut.AddToWishlist(1, 2));
            }
        }
        public void ReturnFalse_WhenUserIdIsIncorrect()
        {
            var options = Utils.GetOptions(nameof(ReturnFalse_WhenUserIdIsIncorrect));
            var user    = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var result = sut.DeleteUser(user.Id + 1);
                Assert.IsFalse(result);
            }
        }
        public void Throw_WhenEmailAlreadyTaken()
        {
            var options = Utils.GetOptions(nameof(Throw_WhenEmailAlreadyTaken));
            var user1   = TestsModelsSeeder.SeedUser();
            var user2   = TestsModelsSeeder.SeedUser2();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user1);
                arrangeContext.Users.Add(user2);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new UserServices(assertContext);
                Assert.ThrowsException <ArgumentException>(() => sut.UpdateUser(2, "User2Name", user1.Email, false, null));
            }
        }
        public void Throw_WhenUserAlreadyExists()
        {
            var options  = Utils.GetOptions(nameof(Throw_WhenUserAlreadyExists));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var userDTO  = TestsModelsSeeder.SeedUserDTO();
            var user     = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new UserServices(assertContext);
                Assert.ThrowsException <ArgumentException>(() => sut.CreateUser(userDTO));
            }
        }
Ejemplo n.º 10
0
        public void Throw_WhenUserIdIsInvalid()
        {
            var options = Utils.GetOptions(nameof(Throw_WhenUserIdIsInvalid));
            var user1   = TestsModelsSeeder.SeedUser();
            var user2   = TestsModelsSeeder.SeedUser2();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user1);
                arrangeContext.Users.Add(user2);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new UserServices(assertContext);
                Assert.ThrowsException <ArgumentNullException>(() => sut.UpdateUser(5, "User2Name", "*****@*****.**", false, null));
            }
        }
Ejemplo n.º 11
0
        public void DeleteUser_WhenIdIsCorrect()
        {
            var options = Utils.GetOptions(nameof(DeleteUser_WhenIdIsCorrect));
            var user    = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var act    = sut.DeleteUser(user.Id);
                var result = assertContext.Users.FirstOrDefault(u => u.UserName == user.UserName);
                Assert.IsTrue(result.IsDeleted);
            }
        }
        public void ReturnTrue_WhenBeerAddedCorrectlyToBeersDrank()
        {
            var options = Utils.GetOptions(nameof(ReturnTrue_WhenBeerAddedCorrectlyToBeersDrank));
            var user    = TestsModelsSeeder.SeedUser();
            var beer    = TestsModelsSeeder.SeedBeer();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(beer);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var result = sut.AddToWishlist(1, 1);
                Assert.IsTrue(result);
            }
        }
Ejemplo n.º 13
0
        public void Throw_WhenEmailTaken()
        {
            var options  = Utils.GetOptions(nameof(Throw_WhenEmailTaken));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var userDTO  = TestsModelsSeeder.SeedUserDTO();
            var user     = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut = new UserServices(assertContext);
                var act = sut.UpdateUser(1, "asdf", userDTO.Email, userDTO.IsBanned, userDTO.BanReason);
                Assert.ThrowsException <ArgumentException>(() => sut.CreateUser(userDTO));
            }
        }
Ejemplo n.º 14
0
        public void ReturnCorrectWishlist_WhenParamsAreValid()
        {
            var options  = Utils.GetOptions(nameof(ReturnCorrectWishlist_WhenParamsAreValid));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var user1    = TestsModelsSeeder.SeedUser();
            var beer1    = TestsModelsSeeder.SeedBeer();
            var beer2    = TestsModelsSeeder.SeedBeer2();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user1);
                arrangeContext.Beers.Add(beer1);
                arrangeContext.Beers.Add(beer2);
                arrangeContext.SaveChanges();
                arrangeContext.Users.FirstOrDefault().Wishlist = new HashSet <WishlistBeer>
                {
                    new WishlistBeer
                    {
                        UserId = 1,
                        BeerId = 1,
                    },
                    new WishlistBeer
                    {
                        UserId = 1,
                        BeerId = 2,
                    }
                };
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var result = sut.GetWishlist(1).ToList();
                Assert.AreEqual(2, result.Count);
                Assert.AreEqual(2, result[0].Id);
                Assert.AreEqual(1, result[1].Id);
            }
        }
        public void AddBeerCorrectly_WhenParamsAreValid()
        {
            var options = Utils.GetOptions(nameof(AddBeerCorrectly_WhenParamsAreValid));
            var user    = TestsModelsSeeder.SeedUser();
            var beer    = TestsModelsSeeder.SeedBeer();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.Beers.Add(beer);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var act    = sut.AddToBeersDrank(1, 1);
                var result = assertContext.Users.FirstOrDefault(u => u.UserName == user.UserName).BeersDrank.ToList();
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual(beer.Id, result[0].BeerId);
            }
        }
Ejemplo n.º 16
0
        public void CorrectlyUpdateUser_WhenDataIsValid()
        {
            var options  = Utils.GetOptions(nameof(CorrectlyUpdateUser_WhenDataIsValid));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var user1    = TestsModelsSeeder.SeedUser();
            var user2    = TestsModelsSeeder.SeedUser2();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user1);
                arrangeContext.Users.Add(user2);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var act    = sut.UpdateUser(2, "User2Name", "*****@*****.**", false, null);
                var result = sut.GetUser(2);
                Assert.AreEqual("User2Name", result.UserName);
                Assert.AreEqual("*****@*****.**", result.Email);
            }
        }
        public void UpdateCorrectReview_When_ParamsValid()
        {
            var options = Utils.GetOptions(nameof(UpdateCorrectReview_When_ParamsValid));
            var review  = TestsModelsSeeder.SeedReview();
            var beer    = TestsModelsSeeder.SeedBeer();
            var user    = TestsModelsSeeder.SeedUser();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Users.Add(user);
                arrangeContext.Add(review);
                arrangeContext.Beers.Add(beer);
                arrangeContext.SaveChanges();
            }
            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new ReviewServices(assertContext);
                var act    = sut.UpdateReviews(1, "NewReviewName", "Changed my mind, I don't like it.", 2);
                var result = assertContext.Reviews.ToList()[0];
                Assert.AreEqual("NewReviewName", result.Name);
                Assert.AreEqual("Changed my mind, I don't like it.", result.Text);
                Assert.AreEqual(2, result.Rating);
            }
        }
Ejemplo n.º 18
0
        public void ReturnCorrectUser_WhenIdIsValid()
        {
            var options  = Utils.GetOptions(nameof(ReturnCorrectUser_WhenIdIsValid));
            var userRole = TestsModelsSeeder.SeedUserRole();
            var user1    = TestsModelsSeeder.SeedUser();
            var user2    = TestsModelsSeeder.SeedUser2();

            using (var arrangeContext = new BeerOverflowContext(options))
            {
                arrangeContext.Roles.Add(userRole);
                arrangeContext.Users.Add(user1);
                arrangeContext.Users.Add(user2);
                arrangeContext.SaveChanges();
            }

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var result = sut.GetUser(2);
                Assert.AreEqual(user2.Id, result.Id);
                Assert.AreEqual(user2.UserName, result.UserName);
                Assert.AreEqual(user2.Email, result.Email);
            }
        }