public void AfterPushChangesDoAppear() { using (TemporaryWorkbook workbook = new TemporaryWorkbook()) { ChangeCoordinator<Account> a = workbook.CreateAccount(AccountType.Asset); a.EditableItem.Name = "Fred"; Guid id = a.EditableItem.AccountID; a.PushChanges(); Asset loaded = workbook.FetchAsset(id); Assert.IsNotNull(loaded); Assert.AreEqual("Fred", loaded.Name); ChangeCoordinator<Asset> loadedLock = workbook.AcquireChangeCoordinator(loaded); loadedLock.EditableItem.Name = "Tom"; // Now, check that the original item ("loaded") is still "Fred" and not "Tom" Assert.AreEqual("Fred", loaded.Name); Assert.AreEqual("Tom", loadedLock.EditableItem.Name); loadedLock.PushChanges(); Assert.AreEqual("Tom", loaded.Name); } }
public void EditAfterFetchingWorks() { using (TemporaryWorkbook workbook = new TemporaryWorkbook()) { ChangeCoordinator<Account> a = workbook.CreateAccount(AccountType.Asset); a.EditableItem.Name = "Fred"; Guid id = a.EditableItem.AccountID; a.PushChanges(); Asset loaded = workbook.FetchAsset(id); Assert.IsNotNull(loaded); Assert.AreEqual("Fred", loaded.Name); ChangeCoordinator<Asset> loadedLock = workbook.AcquireChangeCoordinator(loaded); loadedLock.EditableItem.Name = "Tom"; loadedLock.PushChanges(); } }
public void RemoveAndAddTest() { using (TemporaryWorkbook workbook = new TemporaryWorkbook()) { #region Standard setup code // Create two test accounts ChangeCoordinator<Asset> cashAtBank = workbook.CreateAsset(); ChangeCoordinator<Liability> mortgage = workbook.CreateLiability(); // Create a view over the Cash at Bank transactions TransactionCollectionView credits = new TransactionCollectionView(cashAtBank.EditableItem, workbook.CurrentPeriod, BalanceType.Credit); TransactionCollectionView debits = new TransactionCollectionView(cashAtBank.EditableItem, workbook.CurrentPeriod, BalanceType.Debit); #endregion // Create a transaction ChangeCoordinator<Transaction> t1 = workbook.CreateTransaction(); t1.EditableItem.CreditAccount = cashAtBank.EditableItem; t1.EditableItem.DebitAccount = mortgage.EditableItem; t1.EditableItem.Date = workbook.CurrentPeriod.EndDate.AddDays(-1); t1.EditableItem.Value = 1000M; t1.EditableItem.Particulars = "A test transaction"; t1.PushChanges(); Assert.AreEqual(1, cashAtBank.EditableItem.Transactions.Count, "The underlying transaction should have 1 item."); Assert.AreEqual(1, credits.Count, "The credits collection view should have 1 item"); Assert.AreEqual(0, debits.Count, "The debits collection view should have 0 items"); // Now make it appear in the debits ChangeCoordinator<Transaction> t2 = workbook.AcquireChangeCoordinator(credits[0]); t2.EditableItem.DebitAccount = cashAtBank.EditableItem; t2.EditableItem.CreditAccount = mortgage.EditableItem; t2.PushChanges(); Assert.AreEqual(1, cashAtBank.EditableItem.Transactions.Count, "The underlying transaction should have 1 item."); Assert.AreEqual(0, credits.Count, "The credits collection view should have 0 items"); Assert.AreEqual(1, debits.Count, "The debits collection view should have 1 item"); } }
public void TransactionDateChangedTest() { using (TemporaryWorkbook workbook = new TemporaryWorkbook()) { // Create two test accounts ChangeCoordinator<Asset> cashAtBank = workbook.CreateAsset(); ChangeCoordinator<Liability> mortgage = workbook.CreateLiability(); // Create a transaction ChangeCoordinator<Transaction> t1 = workbook.CreateTransaction(); t1.EditableItem.CreditAccount = cashAtBank.EditableItem; t1.EditableItem.DebitAccount = mortgage.EditableItem; t1.EditableItem.Date = workbook.CurrentPeriod.StartDate.AddDays(-50); t1.EditableItem.Value = 1000M; t1.EditableItem.Particulars = "A test transaction"; t1.PushChanges(); // Now create a view over the Cash at Bank transactions TransactionCollectionView balance = new TransactionCollectionView(cashAtBank.EditableItem, workbook.CurrentPeriod); Assert.AreEqual(1, cashAtBank.EditableItem.Transactions.Count, "The underlying transaction should have 1 item."); Assert.AreEqual(0, balance.Count, "The balance collection view should have 0 items"); Assert.AreEqual(new Balance(1000M, BalanceType.Credit), balance.OpeningBalance, "The opening balance should be 1000 CR"); Assert.AreEqual(new Balance(1000M, BalanceType.Credit), balance.ClosingBalance, "The closing balance should be 1000 CR"); // Now if we change the date, the transactions and balance should update ChangeCoordinator<Transaction> t2 = workbook.AcquireChangeCoordinator(cashAtBank.EditableItem.Transactions[0]); t2.EditableItem.Date = workbook.CurrentPeriod.EndDate.AddDays(-1); t2.PushChanges(); Assert.AreEqual(1, cashAtBank.EditableItem.Transactions.Count, "The underlying transaction should have 1 item."); Assert.AreEqual(1, balance.Count, "The balance collection view should have 1 item"); Assert.AreEqual(new Balance(0M, BalanceType.Debit), balance.OpeningBalance, "The opening balance should be 0 DR"); Assert.AreEqual(new Balance(1000M, BalanceType.Credit), balance.ClosingBalance, "The closing balance should be 1000 CR"); } }