public async Task ChangePassword_Post_ReturnsAView() { var user = HelperObjects.GetUser(); _hash.Setup(hash => hash.Encoder(user.Password, _hashingConfig.Object.Value, user.Salt)).Returns(GetEncodingResult()); _hash.Setup(hash => hash.Encoder("encodedPassword", _hashingConfig.Object.Value)).Returns(GetEncodingResult()); var controller = SetUpBasicUserValidation("1"); var result = await controller.ChangePassword(new SettingsChangePassword() { OldPassword = "******", Password = "******" }); Assert.IsType <ViewResult>(result); }
public async Task ChangePassword_Post_ReturnsError_IfCurrentPasswordDoesNotMatch() { string oldPassword = "******"; var user = HelperObjects.GetUser(); _hash.Setup(hash => hash.Encoder(oldPassword, _hashingConfig.Object.Value, user.Salt)).Returns(GetWrongEncodingResult()); var controller = SetUpBasicUserValidation("1"); var result = await controller.ChangePassword(new SettingsChangePassword() { OldPassword = oldPassword }); Assert.IsType <ViewResult>(result); _repository.Verify(repo => repo.UpdateOneAsync <UserModel, string>(user, null), Times.Never()); }
public async Task Login_Post_ReturnsAnError_IfWrongPassword() { var userViewModel = GetUserViewModel(); var dbUser = HelperObjects.GetUser(); var tupleToReturn = Tuple.Create <string, string>(userViewModel.Password, dbUser.Salt); _repository.Setup(repo => repo.GetById <UserModel, string>(userViewModel.Email, null)).Returns(dbUser); _argonHash.Setup(hash => hash.Encoder(userViewModel.Password, _hashingConfig.Object.Value, dbUser.Salt)).Returns(GetEncodingResult()); var key = "Invalid email or wrong password"; _localizer.Setup(_ => _[key]).Returns(new LocalizedString(key, key)); var controller = new AccountController(_hashingConfig.Object, _repository.Object, _protector.Object, _config.Object, _localizer.Object, _argonHash.Object); var result = await controller.Login(userViewModel); Assert.IsType <ViewResult>(result); Assert.Equal(1, controller.ModelState.ErrorCount); Assert.Equal(key, controller.ModelState.Values.First().Errors.First().ErrorMessage); }
public async Task Login_Post_ReturnsAnError_IfUserNotFound() { _repository.Setup(repo => repo.GetById <UserModel, string>("", null)).Returns(HelperObjects.GetUser()); var key = "Invalid email or wrong password"; _localizer.Setup(_ => _[key]).Returns(new LocalizedString(key, key)); var controller = new AccountController(_hashingConfig.Object, _repository.Object, _protector.Object, _config.Object, _localizer.Object, _argonHash.Object); var result = await controller.Login(GetUserViewModel()); Assert.IsType <ViewResult>(result); Assert.Equal(1, controller.ModelState.ErrorCount); }
private SettingsController SetUpBasicUserValidation(string name, UserStatesEnum state = UserStatesEnum.Active) { _repository.Setup(repo => repo.GetById <UserModel, string>(name, null)).Returns(HelperObjects.GetUser(state)); var controller = CreateController(); controller.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = _user } }; return(controller); }
public void NewAccount_WrongEmailAddress() { var mockedProtector = new Mock <IDataProtector>(); mockedProtector.Setup(protector => protector.Unprotect(It.IsAny <byte[]>())).Returns(Encoding.UTF8.GetBytes("*****@*****.**")); _dataProvider.Setup(s => s.CreateProtector(It.IsAny <string>())).Returns(mockedProtector.Object); _repository.Setup(repo => repo.GetById <UserModel, string>(HelperConstants.TestEmailAddress, null)).Returns(HelperObjects.GetUser(UserStatesEnum.Active)); var controller = new EmailController(_emailService.Object, _message.Object, _dataProvider.Object, _config.Object, _emailAddress.Object, _repository.Object, _emailTemplate.Object, _confirmationEmail.Object, _registrationEmail.Object, _forgotPassword.Object); var result = controller.NewAccount(string.Empty) as StatusCodeResult; Assert.Equal(404, (int)result.StatusCode); }
public async Task Confirm_Success() { _repository.Setup(repo => repo.GetById <UserModel, string>(HelperConstants.TestEmailAddress, null)).Returns(HelperObjects.GetUser(UserStatesEnum.NotConfirmed)); _emailService.Setup(email => email.Send(_message.Object)); _message.SetupProperty(m => m.ToAddresses); _message.Object.ToAddresses = new List <EmailAddress>(); var controller = new EmailController(_emailService.Object, _message.Object, _dataProvider.Object, _config.Object, _emailAddress.Object, _repository.Object, _emailTemplate.Object, _confirmationEmail.Object, _registrationEmail.Object, _forgotPassword.Object); var result = await controller.Confirm(string.Empty); Assert.IsType <ViewResult>(result); }
public async Task Confirm_UserIsActive() { _repository.Setup(repo => repo.GetById <UserModel, string>(HelperConstants.TestEmailAddress, null)).Returns(HelperObjects.GetUser(UserStatesEnum.Active)); var controller = new EmailController(_emailService.Object, _message.Object, _dataProvider.Object, _config.Object, _emailAddress.Object, _repository.Object, _emailTemplate.Object, _confirmationEmail.Object, _registrationEmail.Object, _forgotPassword.Object); var result = await controller.Confirm(string.Empty) as StatusCodeResult; Assert.Equal(404, (int)result.StatusCode); }
public void NewAccount_Success() { _repository.Setup(repo => repo.GetById <UserModel, string>(HelperConstants.TestEmailAddress, null)).Returns(HelperObjects.GetUser(UserStatesEnum.NotConfirmed)); _emailService.Setup(email => email.Send(_message.Object)); _message.SetupProperty(m => m.ToAddresses); _message.Object.ToAddresses = new List <EmailAddress>(); var controller = new EmailController(_emailService.Object, _message.Object, _dataProvider.Object, _config.Object, _emailAddress.Object, _repository.Object, _emailTemplate.Object, _confirmationEmail.Object, _registrationEmail.Object, _forgotPassword.Object); var result = controller.NewAccount(string.Empty); var redirectToAction = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Confirm", redirectToAction.ActionName); Assert.Null(redirectToAction.ControllerName); }