public async Task TestListAccounts() { // Retrieve accounts using provided credentials IEnumerable <OFX.Types.Account> accounts = await AuthenticatedOfxService.ListAccounts(); // At least 1 account must be returned Assert.IsNotNull(accounts); Assert.IsTrue(accounts.Any()); // Ensure each account has a type associated foreach (var account in accounts) { Assert.IsNotNull(account.GetType().Name); } }
/// <summary> /// Retrieve the list of accounts from a financial institution using OFX and return all accounts that are not already present in the database /// </summary> /// <param name="financialInstitution">Financial institution to query</param> /// <param name="fiCredentials">Credentials for financial institution account</param> /// <returns>List of accounts</returns> public static async Task <IEnumerable <Account> > EnumerateNewAccounts( OFX.Types.FinancialInstitution financialInstitution, OFX.Types.Credentials fiCredentials) { using (BackgroundTaskTracker.BeginTask("Retrieving Account Information")) { var ofxService = new OFX2Service(financialInstitution, fiCredentials); var accountList = new List <Account>(); var ofxAccountList = await ofxService.ListAccounts().ConfigureAwait(false); // TODO: If ofxAccountList is null, raise a more detailed exception using (var dataService = new DataService()) { foreach (var ofxAccount in ofxAccountList) { // Convert from OFX account type to db account type and encode account id AccountType accountType = AccountType.Checking; string accountId = ""; if (ofxAccount.GetType() == typeof(OFX.Types.CheckingAccount)) { accountType = AccountType.Checking; accountId = ((OFX.Types.CheckingAccount)ofxAccount).RoutingId + ":" + ofxAccount.AccountId; } else if (ofxAccount.GetType() == typeof(OFX.Types.SavingsAccount)) { accountType = AccountType.Savings; accountId = ((OFX.Types.SavingsAccount)ofxAccount).RoutingId + ":" + ofxAccount.AccountId; } else if (ofxAccount.GetType() == typeof(OFX.Types.CreditCardAccount)) { accountType = AccountType.Creditcard; accountId = ofxAccount.AccountId; } // Look for a matching account in the database if (!dataService.GetAccountByFinancialId(accountId).Any()) { // This account is not already in the DB, add to new account list accountList.Add(new Account { AccountName = accountType + ":" + ofxAccount.AccountId.Substring(ofxAccount.AccountId.Length - 4), AccountType = accountType.ToString(), Currency = "USD", FiAccountId = accountId }); } } } // Return the finalized list of new accounts return(accountList); } }
/// <summary> /// Verify the provided account credentials. Raises an exception if validation fails /// </summary> /// <param name="financialInstitution">Financial institution to query</param> /// <param name="fiCredentials">Credentials for financial institution account</param> /// <returns>List of accounts</returns> public static async Task VerifyAccountCredentials(FinancialInstitution financialInstitution, OFX.Types.Credentials fiCredentials) { using (BackgroundTaskTracker.BeginTask("Verifying Credentials")) { // Convert from data model FI into OFX FI var ofxFinancialInstitition = new OFX.Types.FinancialInstitution(financialInstitution.Name, new Uri(financialInstitution.OfxUpdateUrl), financialInstitution.OfxOrganizationId, financialInstitution.OfxFinancialUnitId); var ofxService = new OFX2Service(ofxFinancialInstitition, fiCredentials); // Call list accounts to validate credentials await ofxService.ListAccounts().ConfigureAwait(false); } }