Inheritance: Workbook, IDisposable
        public void ClosingBalanceTest()
        {
            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.EndDate.AddDays(-1);
                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(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");
            }
        }
Exemplo n.º 2
0
        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 AddToUnderlyingCollectionTest()
        {
            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");
            }
        }
Exemplo n.º 4
0
        public void CurrentPeriodStartEndDateYearlyTest()
        {
            using (TemporaryWorkbook workbook = new TemporaryWorkbook())
            {
                workbook.PeriodLength = PeriodLength.Yearly;
                workbook.PeriodStartDate = DateTime.Now.Date;

                Assert.AreEqual(DateTime.Now.Date, workbook.CurrentPeriod.StartDate);
                Assert.AreEqual(DateTime.Now.Date.AddYears(1).AddDays(-1), workbook.CurrentPeriod.EndDate);
            }
        }
Exemplo n.º 5
0
        public void CreateAccountsReferencesEqualTest()
        {
            using (TemporaryWorkbook workbook = new TemporaryWorkbook())
            {
                ChangeCoordinator<Asset> a1 = workbook.CreateAsset();
                Assert.AreNotEqual(a1.EditableItem.AccountID, Guid.Empty);

                Asset a2 = workbook.FetchAsset(a1.EditableItem.AccountID);
                Assert.AreEqual(a1.EditableItem.AccountID, a2.AccountID);
                Assert.IsTrue(object.ReferenceEquals(a1.EditableItem, a2));
            }
        }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
        public void EditAfterPushChangesThrowsException()
        {
            using (TemporaryWorkbook workbook = new TemporaryWorkbook()) {
                ChangeCoordinator<Account> a = workbook.CreateAccount(AccountType.Asset);
                a.EditableItem.Name = "Fred";
                Guid id = a.EditableItem.AccountID;
                a.PushChanges();

                a.EditableItem.Name = "Fred";
            }
        }
Exemplo n.º 8
0
 public void EditWithinChangeCoordinatorWorks()
 {
     using (TemporaryWorkbook workbook = new TemporaryWorkbook()) {
         ChangeCoordinator<Account> a = workbook.CreateAccount(AccountType.Asset);
         a.EditableItem.Name = "Fred";
     }
 }
Exemplo n.º 9
0
        public void EditOutsideChangeCoordinatorThrowsException()
        {
            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);

                loaded.Name = "Fred";
            }
        }