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_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_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));
            }
        }
예제 #4
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);
            }
        }