Ejemplo n.º 1
0
        public void ShouldHaveValidationErrorWithEmptyOldPassword(string newPassword)
        {
            ResetPasswordUserRequestModel requestModel = new ResetPasswordUserRequestModel()
            {
                NewPassword = newPassword
            };

            _validator.ShouldHaveValidationErrorFor(r => r.NewPassword, requestModel).WithErrorMessage("new password cannot be empty.");
        }
Ejemplo n.º 2
0
        public void ShouldHaveValidationErrorWithGreaterThan60CharactersOldPassword(string newPassword)
        {
            ResetPasswordUserRequestModel requestModel = new ResetPasswordUserRequestModel()
            {
                NewPassword = newPassword
            };

            _validator.ShouldHaveValidationErrorFor(r => r.NewPassword, requestModel).WithErrorMessage("new password must be less than 60 characters.");
        }
Ejemplo n.º 3
0
        public void ShouldHaveValidationErrorWithInvalidLengthCode(string code)
        {
            ResetPasswordUserRequestModel requestModel = new ResetPasswordUserRequestModel()
            {
                Code = code
            };

            _validator.ShouldHaveValidationErrorFor(p => p.Code, requestModel).WithErrorMessage("code must be 8 characters.");
        }
Ejemplo n.º 4
0
        public void ShouldHaveValidationErrorWithEmptyCode(string code)
        {
            ResetPasswordUserRequestModel requestModel = new ResetPasswordUserRequestModel()
            {
                Code = code
            };

            _validator.ShouldHaveValidationErrorFor(p => p.Code, requestModel).WithErrorMessage("code cannot be empty.");
        }
Ejemplo n.º 5
0
        public void ShouldNotHaveValidationErrorWithEqualNewPassword(string newPassword, string newPasswordConfirmation)
        {
            ResetPasswordUserRequestModel requestModel = new ResetPasswordUserRequestModel()
            {
                NewPassword             = newPassword,
                NewPasswordConfirmation = newPasswordConfirmation
            };

            _validator.ShouldNotHaveValidationErrorFor(r => r.NewPasswordConfirmation, requestModel);
        }
Ejemplo n.º 6
0
        public void ShouldHaveValidationErrorWithNotEqualNewPassword(string newPassword, string newPasswordConfirmation)
        {
            ResetPasswordUserRequestModel requestModel = new ResetPasswordUserRequestModel()
            {
                NewPassword             = newPassword,
                NewPasswordConfirmation = newPasswordConfirmation
            };

            _validator.ShouldHaveValidationErrorFor(r => r.NewPasswordConfirmation, requestModel).WithErrorMessage("new password confirmation must be equal to new password.");
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> ResetPassword(ResetPasswordUserRequestModel model)
        {
            try
            {
                await _userService.ResetPassword(model);

                return(Ok());
            }
            catch (Exception exception)
            {
                return(this.HandleExceptionToUserAndLogIfExceptionIsUnexpected(exception));
            }
        }
Ejemplo n.º 8
0
        public async Task ShouldThrowUserNotConfirmedExceptionOnTryResetPasswordWithNotConfirmedUser()
        {
            ResetPasswordUserRequestModel model = new ResetPasswordUserRequestModel()
            {
                Code = "AAAAAAAA", NewPassword = "******", NewPasswordConfirmation = "NEWPASSWORD"
            };

            _userRepositoryMock.GetByResetPasswordCode(Arg.Any <string>()).Returns(_fakeNotConfirmedInsertedUser);

            Exception exception = await Record.ExceptionAsync(() => _userService.ResetPassword(model));

            Assert.IsType <UserNotConfirmedException>(exception);
        }
Ejemplo n.º 9
0
        public async Task ResetPassword(ResetPasswordUserRequestModel model)
        {
            await new ResetPasswordUserValidator().ValidateRequestModelAndThrow(model);

            User user = await _userRepository.GetByResetPasswordCode(model.Code);

            ThrowIfUserIsNullOrNotConfirmed(user);

            user.ResetPassword(_hashUtils.GenerateHash(model.NewPassword));

            _userRepository.Update(user);
            await _userRepository.Save();
        }
Ejemplo n.º 10
0
        public async Task ShouldThrowResourceUserNotFoundExceptionOnTryResetPasswordOnNotExistsUser()
        {
            User notExistsUser = null;
            ResetPasswordUserRequestModel model = new ResetPasswordUserRequestModel()
            {
                Code = "AAAAAAAA", NewPassword = "******", NewPasswordConfirmation = "NEWPASSWORD"
            };

            _userRepositoryMock.GetByResetPasswordCode(Arg.Any <string>()).Returns(notExistsUser);

            Exception exception = await Record.ExceptionAsync(() => _userService.ResetPassword(model));

            Assert.IsType <ResourceNotFoundException>(exception);
        }
Ejemplo n.º 11
0
        public async Task ShouldResetUserPasswordWithSuccess()
        {
            ResetPasswordUserRequestModel model = new ResetPasswordUserRequestModel()
            {
                Code = "AAAAAAAA", NewPassword = "******", NewPasswordConfirmation = "NEWPASSWORD"
            };

            _userRepositoryMock.GetByResetPasswordCode(Arg.Any <string>()).Returns(_fakeConfirmedInsertedUser);

            Exception exception = await Record.ExceptionAsync(() => _userService.ResetPassword(model));

            _hashUtilsMock.Received(1).GenerateHash(Arg.Is <string>(text => text == model.NewPassword));
            _userRepositoryMock.Received(1).Update(Arg.Any <User>());
            await _userRepositoryMock.Received(1).Save();

            Assert.Null(exception);
        }