Exemplo n.º 1
0
        public void AddUser_should_save()
        {
            string username = "******" + Guid.NewGuid();

            var user = new User
            {
                 Email = "*****@*****.**",
                 FirstName = "john",
                 IsActive = true,
                 LastName = "haigh",
                 PasswordHash = "asdf",
                 Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Test
            repoUser.ShouldNotBeNull();

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            Assert.IsNull(userFound2, "Tried to get user but the user was found");
        }
Exemplo n.º 2
0
        public void AddUser_should_save_with_user_properties()
        {
            string username = "******" + Guid.NewGuid();

            var user = new User
            {
                Email = "*****@*****.**",
                FirstName = "john",
                IsActive = true,
                LastName = "haigh",
                PasswordHash = "asdf",
                Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Test
            repoUser.Email.ShouldEqual(user.Email);
            repoUser.FirstName.ShouldEqual(user.FirstName);
            repoUser.LastName.ShouldEqual(user.LastName);
            repoUser.IsActive.ShouldEqual(user.IsActive);
            repoUser.PasswordHash.ShouldEqual(user.PasswordHash);
            repoUser.Username.ShouldEqual(user.Username);

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            userFound2.ShouldBeNull();
        }
Exemplo n.º 3
0
        public void GetUserByUsername_should_not_getuser()
        {
            var svc = new UserService();

            // main test

            var userAssert = svc.GetUserByUsername("badusername");

            userAssert.ShouldBeNull();
        }
Exemplo n.º 4
0
        public void GetUserByUsername_should_getuser()
        {
            string username = "******" + Guid.NewGuid();

            var user = new User
            {
                Email = "*****@*****.**",
                FirstName = "john",
                IsActive = true,
                LastName = "haigh",
                PasswordHash = "asdf",
                Username = username
            };

            var svc = new UserService();
            svc.AddUser(user);

            // main test
            var userAssert = svc.GetUserByUsername(username);

            userAssert.ShouldNotBeNull();

            // Assert
            var repo = new UserRepository();

            var repoUser = repo.Find(u => u.Username == username).FirstOrDefault();

            // Cleanup user
            repo.Delete(repoUser);
            repo.Save();

            var results2 = repo.Find(u => u.Username == username);
            var userFound2 = results2.FirstOrDefault();

            userFound2.ShouldBeNull();
        }