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);
            }
        }
        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));
            }
        }
        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));
            }
        }
예제 #4
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 ReturnCorrectUser_WhenParamsAreValid()
        {
            var options  = Utils.GetOptions(nameof(ReturnCorrectUser_WhenParamsAreValid));
            var userDTO  = TestsModelsSeeder.SeedUserDTO();
            var userRole = TestsModelsSeeder.SeedUserRole();

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

            using (var assertContext = new BeerOverflowContext(options))
            {
                var sut    = new UserServices(assertContext);
                var act    = sut.CreateUser(userDTO);
                var result = assertContext.Users.FirstOrDefault(user => user.UserName == userDTO.UserName);
                Assert.AreEqual(userDTO.Id, result.Id);
                Assert.AreEqual(userDTO.UserName, result.UserName);
                Assert.AreEqual(userDTO.Email, result.Email);
            }
        }
예제 #6
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);
            }
        }
        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);
            }
        }