Example #1
0
        public void TestAddAccountFromFi()
        {
            // Mock setup for DataService
            var mockAccountSet = new Mock<DbSet<Account>>();
            var mockFiSet = new Mock<DbSet<FinancialInstitution>>();
            var mockFiUserSet = new Mock<DbSet<FinancialInstitutionUser>>();
            var mockContext = new Mock<SoCashDbContext>();
            mockContext.Setup(m => m.Accounts).Returns(mockAccountSet.Object);
            mockContext.Setup(m => m.FinancialInstitutions).Returns(mockFiSet.Object);
            mockContext.Setup(m => m.FinancialInstitutionUsers).Returns(mockFiUserSet.Object);

            // Account to add
            var newAccount = new Account
            {
                AccountName = "Test Account",
                AccountType = AccountType.Checking.ToString(),
                Currency = "USD"
            };

            // Dummy FI
            var financialInstitution = new OFX.Types.FinancialInstitution("Test FI", new Uri("http://test.com/"), "Test Org ID", "Test Unit ID");

            // Dummy FI User
            var financialInstitutionUser = new FinancialInstitutionUser { UserId = "Test User", Password = "******" };

            // Add the account in a transaction
            using (var service = new DataService(mockContext.Object))
            {

                service.AddAccount(newAccount, financialInstitution, financialInstitutionUser);
            }

            // Verify that the service added 1 account, 1 fi and 1 fi user
            mockAccountSet.Verify(m => m.Add(newAccount), Times.Once());
            mockFiSet.Verify(m => m.Add(It.IsAny<FinancialInstitution>()), Times.Once());
            mockFiUserSet.Verify(m => m.Add(financialInstitutionUser), Times.Once());

            // Verify that the transaction ended properly
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
Example #2
0
        /// <summary>
        /// Create an automatic-update account from the provided information
        /// </summary>
        /// <returns>Created account</returns>
        protected Account CreateAutomaticAccount(object passwordEntry)
        {
            // Retrieve password from entry
            var passwordBox = passwordEntry as PasswordBox;
            var password = passwordBox?.Password;

            // Attach account name to account
            SelectedAccount.AccountName = AccountName;

            Account newAccount;
            using (var dataService = new DataService())
            {
                // Add to database
                newAccount = dataService.AddAccount(SelectedAccount, SelectedFinancialInstitution,
                    new FinancialInstitutionUser
                    {
                        UserId = FinancialInstitutionUsername,
                        Password = password
                    }
                    );
            }

            // Start an automatic background retrieval of transactions for this account
            var unwaitedTask = UpdateService.DownloadOfxTransactionsForAccount(newAccount);
            unwaitedTask.ConfigureAwait(false);

            return newAccount;
        }
Example #3
0
        /// <summary>
        /// Create a manual-entry account from the provided information
        /// </summary>
        /// <returns>Created account</returns>
        protected Account CreateManualAccount()
        {
            // Fill in account data
            var newAccount = new Account
            {
                AccountName = AccountName,
                AccountType = SelectedAccountType,
                Currency = "USD"
            };

            using (var dataService = new DataService())
            {
                // Add to database
                dataService.AddAccount(newAccount);
            }

            return newAccount;
        }
Example #4
0
        public void TestAddManualUpdateAccount()
        {
            // Mock setup for DataService
            var mockSet = new Mock<DbSet<Account>>();
            var mockContext = new Mock<SoCashDbContext>();
            mockContext.Setup(m => m.Accounts).Returns(mockSet.Object);

            // Account to add
            var newAccount = new Account
            {
                AccountName = "Test Account",
                AccountType = AccountType.Checking.ToString(),
                Currency = "USD"
            };

            // Add the account in a transaction
            using (var service = new DataService(mockContext.Object))
            {

                service.AddAccount(newAccount);
            }

            // Verify that the service added the account on the mock db exactly once
            mockSet.Verify(m => m.Add(newAccount), Times.Once());

            // Verify that the transaction ended properly
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }