Exemple #1
0
        public async Task GivenAValidUser_ShouldAuthenticateAsync()
        {
            var password          = "******";
            var passwordEncrypted = HashServices.CreatePasswordEncrypted(password);

            var userModel = _fixture.Build <AuthenticateUser>()
                            .With(u => u.Password, password)
                            .Create();

            var user = _fixture.Build <User>()
                       .With(u => u.PasswordHash, passwordEncrypted.passwordHash)
                       .With(u => u.PasswordSalt, passwordEncrypted.passwordSalt)
                       .Create();

            var userDAOMock = new Mock <IUserDAO>();

            userDAOMock.Setup(m => m.BuscarPorUsername(It.IsAny <string>())).Returns(Task.FromResult(user));

            var _userAuthenticateService = new UserAuthenticateService(userDAOMock.Object);

            UserSensitive userResponse = await _userAuthenticateService.AuthenticateAsync(userModel);

            userResponse.Should().NotBeNull();
            userResponse.Username.Should().Be(user.Username);
        }
        private static IList <User> CreateUsers()
        {
            IList <User> UsersList = new List <User>();

            var passwordEncrypted = HashServices.CreatePasswordEncrypted("senha1");
            var user1             = new User {
                FirstName = "Daniel", LastName = "Souza", Username = "******", PasswordHash = passwordEncrypted.passwordHash, PasswordSalt = passwordEncrypted.passwordSalt
            };

            UsersList.Add(user1);

            passwordEncrypted = HashServices.CreatePasswordEncrypted("senha1");
            var user2 = new User {
                FirstName = "Izabela", LastName = "Souza", Username = "******", PasswordHash = passwordEncrypted.passwordHash, PasswordSalt = passwordEncrypted.passwordSalt
            };

            UsersList.Add(user2);

            passwordEncrypted = HashServices.CreatePasswordEncrypted("senha2");
            var user3 = new User {
                FirstName = "Carlos", LastName = "Oliveira", Username = "******", PasswordHash = passwordEncrypted.passwordHash, PasswordSalt = passwordEncrypted.passwordSalt
            };

            UsersList.Add(user3);

            _usersList = UsersList;

            return(UsersList);
        }
        private User CreateUserModel()
        {
            var password          = _fixture.Create <string>();
            var passwordEncrypted = HashServices.CreatePasswordEncrypted(password);

            var user = _fixture.Build <User>()
                       .With(u => u.PasswordHash, passwordEncrypted.passwordHash)
                       .With(u => u.PasswordSalt, passwordEncrypted.passwordSalt)
                       .Without(u => u.Id)
                       .Create();

            return(user);
        }