public void AddUser_should_store_a_user()
        {
            // Arrange
            var expectedUser = new User()
            {
                Id = Guid.NewGuid(),
                Email = "*****@*****.**",
                Firstname = "Nano",
                Lastname = "Smith",
                Password = "******"
            };

            var repository = CreateUserRepository();

            // Act
            repository.AddUser(expectedUser);

            // Assert
            IEnumerable<User> users = repository.GetUsers();

            Assert.That(users.Count(), Is.EqualTo(1));

            User actualUser = users.FirstOrDefault();
            Assert.That(actualUser.Id, Is.EqualTo(expectedUser.Id));
            Assert.That(actualUser.Email, Is.EqualTo(expectedUser.Email));
            Assert.That(actualUser.Firstname, Is.EqualTo(expectedUser.Firstname));
            Assert.That(actualUser.Lastname, Is.EqualTo(expectedUser.Lastname));
            Assert.That(actualUser.Password, Is.EqualTo(expectedUser.Password)); // password property is updated
        }
        public void UpdateUser(User user, bool passwordHasChanged)
        {
            if (passwordHasChanged)
                user.Password = User.HashPassword(user.Password);

            RedisUserClient.Store(user);
        }
        public void AddUserToTeam(Team team, User user)
        {
            if (team == null)
                throw new ArgumentNullException("team");

            if (user == null)
                throw new ArgumentNullException("user");

            team.UserIds.Add(user.Id);
            RedisTeamClient.Store(team);
        }
        public void DeleteUser_should_remove_the_user()
        {
            // Arrange
            string plainTextPassword = "******";
            var user = new User()
            {
                Id = Guid.NewGuid(),
                Email = "*****@*****.**",
                Password = plainTextPassword
            };

            var repository = CreateUserRepository();
            repository.AddUser(user);

            // Act
            repository.DeleteUser(user);

            // Assert
            IEnumerable<User> users = repository.GetUsers();
            Assert.That(users.Count(), Is.EqualTo(0));
        }
        public void AddUser_should_hash_the_password()
        {
            // Arrange
            string plainTextPassword = "******";
            var expectedUser = new User()
            {
                Id = Guid.NewGuid(),
                Email = "*****@*****.**",
                Password = plainTextPassword
            };

            var repository = CreateUserRepository();

            // Act
            repository.AddUser(expectedUser);

            // Assert
            IEnumerable<User> users = repository.GetUsers();
            User actualUser = users.FirstOrDefault();
            Assert.That(actualUser.Password, Is.Not.EqualTo(plainTextPassword));
        }
 public void DeleteUser(User user)
 {
     RedisUserClient.Delete(user);
 }
 public void AddUser(User user)
 {
     user.Password = User.HashPassword(user.Password);
     RedisUserClient.Store(user);
 }
        public void RemoveUserFromTeam(Team team, User user)
        {
            if (team == null)
                throw new ArgumentNullException("team");

            if (user == null)
                throw new ArgumentNullException("user");

            team.UserIds.Remove(user.Id);
            RedisTeamClient.Store(team);
        }
        private User AddJohnDoe()
        {
            var user = new User() { Id = Guid.NewGuid(), Firstname = "John", Lastname = "Doe", Email = "*****@*****.**" };
            using (var userRepository = CreateUserRepository())
            {
                userRepository.AddUser(user);
            }

            return user;
        }
        public void UpdateUser_should_store_the_updated_details()
        {
            // Arrange
            var newUser = new User()
            {
                Id = Guid.NewGuid(),
                Email = "*****@*****.**",
                Firstname = "Nano",
                Lastname = "Smith",
                Password = "******"
            };

            var repository = CreateUserRepository();
            repository.AddUser(newUser);

            // Act
            IEnumerable<User> users = repository.GetUsers();
            User userToUpdate = users.FirstOrDefault();
            userToUpdate.Firstname = "Updated firstname";
            userToUpdate.Lastname = "Updated lastname";
            userToUpdate.Email = "Updated email";

            repository.UpdateUser(userToUpdate, false);

            // Assert
            users = repository.GetUsers();
            User actualUser = users.FirstOrDefault();

            Assert.That(actualUser.Id, Is.EqualTo(userToUpdate.Id));
            Assert.That(actualUser.Email, Is.EqualTo(userToUpdate.Email));
            Assert.That(actualUser.Firstname, Is.EqualTo(userToUpdate.Firstname));
            Assert.That(actualUser.Lastname, Is.EqualTo(userToUpdate.Lastname));
            Assert.That(actualUser.Password, Is.EqualTo(userToUpdate.Password));
        }
        public void UpdateUser_should_hash_the_new_password_when_set()
        {
            // Arrange
            string newPlainTextPassword = "******";
            var newUser = new User()
            {
                Id = Guid.NewGuid(),
                Email = "*****@*****.**",
                Firstname = "Nano",
                Lastname = "Smith",
                Password = "******"
            };

            var repository = CreateUserRepository();
            repository.AddUser(newUser);

            IEnumerable<User> users = repository.GetUsers();

            // Act
            User updatedUser = users.FirstOrDefault();
            updatedUser.Password = newPlainTextPassword;

            repository.UpdateUser(updatedUser, true);

            // Assert
            users = repository.GetUsers();
            User userFromRepo = users.FirstOrDefault();
            Assert.That(userFromRepo.Password, Is.Not.EqualTo(newPlainTextPassword));
        }