public void TestUpdateFiUser() { // FiUser for test var fiUser = new FinancialInstitutionUser {UserId = "OriginalId", Password = "******"}; // Mock setup for DataService var mockFiUserSet = new Mock<DbSet<FinancialInstitutionUser>>(); var mockContext = new Mock<SoCashDbContext>(); mockContext.Setup(m => m.Set<FinancialInstitutionUser>()).Returns(mockFiUserSet.Object); // Update the user using (var service = new DataService(mockContext.Object)) service.UpdateFiUser(fiUser); // Verify that the service attached the user on the mock db exactly once mockContext.Verify(m => m.SetModified(fiUser), Times.Once()); // Verify that the transaction ended properly mockContext.Verify(m => m.SaveChanges(), Times.Once()); }
/// <summary> /// Verify the user provided credentials against the configured FI. If they verify /// </summary> public async Task VerifyAndSaveCredentials(object passwordEntry) { // Retrieve password from entry var passwordBox = passwordEntry as PasswordBox; var password = passwordBox?.Password; // Store the account we're updating in case it changes while we're validating var updateAccount = SelectedAccount; // Form credentials into proper type for verification var credentials = new OFX.Types.Credentials(FiUserName, password); // Verify credentials and update if verification fails try { await UpdateService.VerifyAccountCredentials( SelectedAccount.FinancialInstitutionUser.FinancialInstitution, credentials).ConfigureAwait(false); } catch (Exception) { // Verify failed CredentialsFailed = true; CredentialsVerified = false; return; } // Verification OK CredentialsFailed = false; // Update FI user updateAccount.FinancialInstitutionUser.UserId = credentials.UserId; updateAccount.FinancialInstitutionUser.Password = credentials.Password; using (var dataService = new DataService()) { // Save to DB dataService.UpdateFiUser(updateAccount.FinancialInstitutionUser); } // Saved CredentialsVerified = true; }