public async Task ChangeEmail_UserEmailChanges_EmailChangeCompletes(int userId, string password, string email) { 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.ChangeEmailAsync(password, email, userId); if (!result) { Assert.IsTrue(false); } UserAccountModel model = await userAccountRepository.GetAccountById(userId); if (model.EmailAddress == email) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }
public async Task ChangeEmail_UserEmailChanges_EmailChangeCompletes(int userId, string password, string email) { Mock <IUserAccountRepository> mockUserAccountRepository = new Mock <IUserAccountRepository>(); Mock <IUserAccountSettingsRepository> mockUserAccountSettingsRepository = new Mock <IUserAccountSettingsRepository>(); Mock <IAuthenticationService> mockAuthenticationService = new Mock <IAuthenticationService>(); Mock <ICryptographyService> mockCryptographyService = new Mock <ICryptographyService>(); mockUserAccountRepository.Setup(x => x.UpdateAccountEmail(userId, email)); mockAuthenticationService.Setup(x => x.AuthenticatePasswordWithUserId(password, userId)).Returns(Task.FromResult(true)); IAccountSettingsService userAccountSettingsManager = new AccountSettingsService(mockUserAccountRepository.Object, mockUserAccountSettingsRepository.Object, mockCryptographyService.Object, mockAuthenticationService.Object); bool result = await userAccountSettingsManager.ChangeEmailAsync(password, email, userId); if (result == true) { Assert.IsTrue(true); } else { Assert.IsTrue(false); } }