public async Task ChangePasswordTest_UserPasswordChanges_PasswordChangeCompletes(int userId, string password, string newPassword) { IDataGateway dataGateway = new SQLServerGateway(); IConnectionStringData connectionString = new ConnectionStringData(); IUserAccountRepository userAccountRepository = new UserAccountRepository(dataGateway, connectionString); IUserAccountSettingsRepository userAccountSettingsRepository = new UserAccountSettingRepository(dataGateway, connectionString); ICryptographyService cryptographyService = new CryptographyService(userAccountRepository); IAuthenticationService authenticationService = new AuthenticationService(userAccountRepository); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(userAccountRepository, userAccountSettingsRepository, cryptographyService, authenticationService); bool result = await userAccountSettingsManager.ChangePasswordAsync(password, newPassword, userId); if (!result) { Assert.IsTrue(false); } UserAccountModel model = await userAccountRepository.GetAccountById(userId); UserAccountRepository userAccountRepo = new UserAccountRepository(new SQLServerGateway(), new ConnectionStringData()); string encryptedNewPassword = await cryptographyService.EncryptPasswordAsync(newPassword, userId); if (model.Password == encryptedNewPassword) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task ChangePasswordTest_UserPasswordChanges_PasswordChangeCompletes(int userId, string password, string newPassword) { Mock <IUserAccountRepository> mockUserAccountRepository = new Mock <IUserAccountRepository>(); Mock <IUserAccountSettingsRepository> mockUserAccountSettingsRepository = new Mock <IUserAccountSettingsRepository>(); Mock <IAuthenticationService> mockAuthenticationService = new Mock <IAuthenticationService>(); Mock <ICryptographyService> mockCryptographyService = new Mock <ICryptographyService>(); mockAuthenticationService.Setup(x => x.AuthenticatePasswordWithUserId(password, userId)).Returns(Task.FromResult(true)); mockCryptographyService.Setup(x => x.newPasswordEncryptAsync(newPassword, userId)).Returns(Task.FromResult(true)); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(mockUserAccountRepository.Object, mockUserAccountSettingsRepository.Object, mockCryptographyService.Object, mockAuthenticationService.Object); bool result = await userAccountSettingsManager.ChangePasswordAsync(password, newPassword, userId); if (result == true) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }