public void createSubAccount() { Budgeteer.Account.Db.execute("DELETE FROM accounts;"); Budgeteer.Account parent = new Budgeteer.Account(); parent.OpeningBalance = 0; Budgeteer.Account child = new Budgeteer.Account(); child.OpeningBalance = 0; Budgeteer.Account grandchild = new Budgeteer.Account(); grandchild.OpeningBalance = 0; parent.addEnvelope(child); child.addEnvelope(grandchild); // Test structure Assert.AreEqual(parent.Name, child.ParentAccount.Name); Assert.AreEqual(parent.Name, grandchild.ParentAccount.ParentAccount.Name); Assert.AreEqual(child.Name, grandchild.ParentAccount.Name); // Also test implementation of Equals Assert.AreEqual(parent, child.ParentAccount); Assert.AreEqual(child, grandchild.ParentAccount); Assert.IsTrue(parent.SubAccounts.Contains(child)); Assert.IsTrue(child.SubAccounts.Contains(grandchild)); // Test each parent can reference its children Assert.AreEqual(1, parent.SubAccounts.Count); Assert.AreEqual(1, child.SubAccounts.Count); Assert.AreEqual(0, grandchild.SubAccounts.Count); }
public void testBalanceCalculations() { Budgeteer.Account acct = new Budgeteer.Account(); acct.OpeningBalance = 100; acct.save(); Budgeteer.Transaction t1 = new Budgeteer.Transaction(); t1.Amount = 18.94; t1.SourceAccount = acct; t1.Payee = "HEB"; t1.save(); acct.Transactions.Add(t1); Assert.AreEqual(System.Math.Round(81.06, 2), acct.Balance); Budgeteer.Account destAcct = new Budgeteer.Account(); destAcct.OpeningBalance = 236.57; Budgeteer.Transaction t2 = new Budgeteer.Transaction(); t2.Amount = 12.45; t2.SourceAccount = acct; t2.DestinationAccount = destAcct; acct.Transactions.Add(t2); destAcct.Transactions.Add(t2); Assert.AreEqual(System.Math.Round(249.02, 2), destAcct.Balance); Assert.AreEqual(System.Math.Round(68.61, 2), acct.Balance); }
public void createdAccountIncrementsAccountNumber() { Budgeteer.Account acct1 = new Budgeteer.Account(); acct1.OpeningBalance = 0; Assert.AreEqual(acct1.Name, "Account_1"); Budgeteer.Account acct2 = new Budgeteer.Account(); acct2.OpeningBalance = 0; Assert.AreEqual(acct2.Name, "Account_2"); }
public void testSettingSourceAccount() { Budgeteer.Account acct1 = new Budgeteer.Account(); acct1.OpeningBalance = 300; acct1.Name = "test setting source account"; acct1.save(); Budgeteer.Transaction t1 = new Budgeteer.Transaction(); t1.Amount = 100; t1.Memo = "Cheese"; t1.Payee = "HEB"; t1.SourceAccount = acct1; t1.save(); acct1.reload(); Assert.AreEqual(200, acct1.Balance); Assert.AreEqual(acct1.Id, t1.SourceAccountId); }
public void testAccountPersistence() { Budgeteer.Account.ensureSchema(); Assert.IsTrue(System.IO.File.Exists("budgeteer.bdg")); Budgeteer.Account.Db.execute("DELETE FROM accounts;"); Budgeteer.Account acct1 = new Budgeteer.Account(); acct1.OpeningBalance = 0; Assert.IsTrue(acct1.save()); Budgeteer.Account.Db.close(); Budgeteer.Account acct2 = Budgeteer.Account.findByName(acct1.Name); Budgeteer.Account acct3 = Budgeteer.Account.findById(acct1.Id); Budgeteer.Account.Db.close(); Assert.IsNotNull(acct2); Assert.AreEqual(acct1, acct2); Assert.AreEqual(acct1, acct3); Assert.AreEqual(acct2, acct3); }
public void testReload() { Budgeteer.Account acct1 = new Budgeteer.Account(); acct1.Name = "Test reload!"; acct1.OpeningBalance = 345; acct1.save(); int id = acct1.Id; string name = acct1.Name; double openingBalance = acct1.OpeningBalance; int parentAccountId = acct1.ParentAccountId; acct1.Name = "this goes away when reloaded"; acct1.reload(); Assert.AreEqual(id, acct1.Id); Assert.AreEqual(name, acct1.Name); Assert.AreEqual(openingBalance, acct1.OpeningBalance); Assert.AreEqual(parentAccountId, acct1.ParentAccountId); }
public void testTransactionListVsTransactions() { Budgeteer.Account parent = new Budgeteer.Account(); parent.OpeningBalance = 100; Budgeteer.Transaction t = new Budgeteer.Transaction(); t.Amount = 95; t.SourceAccount = parent; parent.Transactions.Add(t); Assert.AreEqual(5, parent.Balance); Budgeteer.Account child1 = new Budgeteer.Account(); child1.OpeningBalance = 200; t = new Budgeteer.Transaction(); t.Amount = 95; t.SourceAccount = child1; child1.Transactions.Add(t); Assert.AreEqual(105, child1.Balance); child1.ParentAccount = parent; parent.SubAccounts.Add(child1); Assert.AreEqual(110, parent.Balance); Budgeteer.Account child2 = new Budgeteer.Account(); child2.OpeningBalance = 300; t = new Budgeteer.Transaction(); t.Amount = 95; t.SourceAccount = child2; child2.Transactions.Add(t); Assert.AreEqual(205, child2.Balance); child2.ParentAccount = child1; child1.SubAccounts.Add(child2); Assert.AreEqual(310, child1.Balance); Assert.AreEqual(315, parent.Balance); List<Budgeteer.Transaction> transactionList = parent.TransactionList; Assert.AreEqual(3, transactionList.Count); Assert.AreEqual(1, parent.Transactions.Count); }
public void testLoadingSubAccountsAndParentBalance() { Budgeteer.Account.Db.execute("DELETE FROM accounts;"); Budgeteer.Account parent = new Budgeteer.Account(); parent.OpeningBalance = 100; Assert.IsTrue(parent.save()); Budgeteer.Account[] childAccounts = new Budgeteer.Account[5]; for (int i = 0; i < 5; ++i) { childAccounts[i] = new Budgeteer.Account(); childAccounts[i].OpeningBalance = 100 * i; childAccounts[i].ParentAccount = parent; Assert.IsTrue(childAccounts[i].save()); } Assert.AreEqual(5, parent.SubAccounts.Count); Assert.AreEqual(1100, System.Math.Round(parent.Balance, 2)); }
public void testSettingParentAccountIdOrParentNullsOther() { Budgeteer.Account.ensureSchema(); Assert.IsTrue(System.IO.File.Exists("budgeteer.bdg")); Budgeteer.Account.Db.execute("DELETE FROM accounts;"); Budgeteer.Account parent = new Budgeteer.Account(); parent.OpeningBalance = 0; Assert.IsTrue(parent.save()); Budgeteer.Account child = new Budgeteer.Account(); child.OpeningBalance = 100; Assert.IsTrue(child.save()); Budgeteer.Account newParent = new Budgeteer.Account(); newParent.OpeningBalance = 200; Assert.IsTrue(newParent.save()); child.ParentAccount = parent; Assert.AreEqual(parent.Id, child.ParentAccountId); Assert.IsTrue(child.save()); child = Budgeteer.Account.findById(child.Id); Assert.AreEqual(parent, child.ParentAccount); child.ParentAccountId = newParent.Id; Assert.AreEqual(newParent, child.ParentAccount); }