private ViewResult ConfirmValidityOfAccount(SettingsViewModel model) { DeleteAccountSettingsViewModel deleteAccountSettingsViewModel = new DeleteAccountSettingsViewModel() { EmailAddress = model.EmailAddress, Password = model.Password }; var verifyResponse = _accountMediator.VerifyAccountSettings(UserContext.CandidateId, deleteAccountSettingsViewModel); ModelState.Clear(); switch (verifyResponse.Code) { case AccountMediatorCodes.ValidateUserAccountBeforeDelete.ValidationError: verifyResponse.ValidationResult.AddToModelState(ModelState, string.Empty); return(View("Settings", model)); case AccountMediatorCodes.ValidateUserAccountBeforeDelete.HasError: SetUserMessage(verifyResponse.Message.Text, verifyResponse.Message.Level); return(View("Settings", model)); case AccountMediatorCodes.ValidateUserAccountBeforeDelete.Ok: return(View("ConfirmAccountDeletion", model)); default: throw new InvalidMediatorCodeException(verifyResponse.Code); } }
public void SaveValidationErrorTest() { var settingsViewModel = new SettingsViewModel(); var deleteAccountSettingsViewModel = new DeleteAccountSettingsViewModel(); var accountProvider = new Mock <IAccountProvider>(); accountProvider.Setup(x => x.GetSettingsViewModel(It.IsAny <Guid>())).Returns(new SettingsViewModel()); var accountMediator = new AccountMediatorBuilder().With(accountProvider.Object).Build(); deleteAccountSettingsViewModel.EmailAddress = settingsViewModel.EmailAddress; deleteAccountSettingsViewModel.Password = settingsViewModel.Password; var response = accountMediator.VerifyAccountSettings(Guid.NewGuid(), deleteAccountSettingsViewModel); response.Code.Should().Be(AccountMediatorCodes.ValidateUserAccountBeforeDelete.ValidationError); response.ValidationResult.Should().NotBeNull(); }
public MediatorResponse VerifyAccountSettings(Guid candidateId, DeleteAccountSettingsViewModel deleteAccountSettingsViewModel) { var validationResult = _deleteAccountSettingsViewModelServerValidator.Validate(deleteAccountSettingsViewModel); try { if (!validationResult.IsValid) { return(GetMediatorResponse(AccountMediatorCodes.ValidateUserAccountBeforeDelete.ValidationError, deleteAccountSettingsViewModel, validationResult)); } var candidate = _candidateService.Authenticate(deleteAccountSettingsViewModel.EmailAddress, deleteAccountSettingsViewModel.Password); if (candidate != null && candidate.EntityId == candidateId) { return(GetMediatorResponse(AccountMediatorCodes.ValidateUserAccountBeforeDelete.Ok, deleteAccountSettingsViewModel)); } } catch (Exception) { return(GetMediatorResponse(AccountMediatorCodes.ValidateUserAccountBeforeDelete.HasError, deleteAccountSettingsViewModel, validationResult, MyApplicationsPageMessages.InvalidUserAccount, UserMessageLevel.Error)); } return(GetMediatorResponse(AccountMediatorCodes.ValidateUserAccountBeforeDelete.HasError, deleteAccountSettingsViewModel, validationResult, MyApplicationsPageMessages.InvalidUserAccount, UserMessageLevel.Error)); }
public void MatchAndAuthenticateUserCredentialsTest_Failing() { var candidateId = Guid.NewGuid(); var deleteAccountSettingsViewModel = new DeleteAccountSettingsViewModel { EmailAddress = "*****@*****.**", Password = "******" }; var candidate = new Candidate { EntityId = Guid.NewGuid() }; var candidateService = new Mock <ICandidateService>(); candidateService .Setup(cs => cs.Authenticate(deleteAccountSettingsViewModel.EmailAddress, deleteAccountSettingsViewModel.Password)) .Returns(candidate); var accountMediator = new AccountMediatorBuilder().With(candidateService).Build(); var response = accountMediator.VerifyAccountSettings(candidateId, deleteAccountSettingsViewModel); response.Code.Should().Be(AccountMediatorCodes.ValidateUserAccountBeforeDelete.HasError); }