Exemplo n.º 1
0
        public void Account_count_returns_the_correct_result()
        {
            Account account1;
            Account account2;

            account1 = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };

            account2 = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };

            var accountCategory = new AccountCategory
            {
                Name = "Other",
                Colour = "Orange",
                IsValid = true,
            };

            Assert.AreEqual(accountCategory.AccountCount(), 0);

            account1.setCategory(accountCategory);
            Assert.AreEqual(accountCategory.AccountCount(), 1);

            account2.setCategory(accountCategory);
            Assert.AreEqual(accountCategory.AccountCount(), 2);

            var accountCategory2 = new AccountCategory
            {
                Name = "New One",
                Colour = "Pink",
                IsValid = true,
            };

            account1.setCategory(accountCategory2);
            Assert.AreEqual(accountCategory.AccountCount(), 1);
            Assert.AreEqual(accountCategory2.AccountCount(), 1);
        }
Exemplo n.º 2
0
        public void Can_create_new_Account()
        {
            var account = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };
            account.setType(_accountType1);
            account.setCategory(_accountCategory);

            Assert.IsNotNull(account);
            Assert.AreEqual(account.Id, Guid.Empty);
            Assert.AreEqual(account.Category.Id, Guid.Empty);
            Assert.AreEqual(account.Category.Colour, "Orange");
            Assert.AreEqual(account.Category.IsValid, true);
            Assert.AreEqual(account.Category.Name, "Other");
            Assert.AreEqual(account.IsValid, true);
            Assert.AreEqual(account.Name, "Bank Account");
            Assert.AreEqual(account.Type.Id, Guid.Empty);
            Assert.AreEqual(account.Type.IsDestination, true);
            Assert.AreEqual(account.Type.IsSource, true);
            Assert.AreEqual(account.Type.IsValid, true);
            Assert.AreEqual(account.Type.Name, "Asset");
        }
        public void Can_add_new_account()
        {
            var account = new Account { Name = "Credit Card", IsValid = true };
            account.setType(_accountType1);
            account.setCategory(_accountCategory);

            IAccountRepository Arepository = new AccountRepository();

            Arepository.Add(account);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<Account>(account.Id);
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(account, fromDb);
                Assert.AreEqual(account.Name, fromDb.Name);
                Assert.AreEqual(account.IsValid, fromDb.IsValid);
                Assert.AreEqual(account.Type.Name, fromDb.Type.Name);
                Assert.AreEqual(account.Category.Name, fromDb.Category.Name);

                Assert.IsTrue(IsInCollection(account, account.Category.Accounts));
                Assert.IsTrue(IsInCollection(account, account.Type.Accounts));
            }
        }
Exemplo n.º 4
0
        public void Count_Destination_Items_returns_correct_result()
        {
            var account = new Account
            {
                Name = "Test Account",
                IsValid = true,

            };
            account.setType(_accountType1);
            account.setCategory(_accountCategory);

            Assert.AreEqual(account.ItemsDestinationCount(), 0);

            _item.SetDestination(account);
            Assert.AreEqual(account.ItemsDestinationCount(), 1);

            _item.SetDestination(account);
            Assert.AreEqual(account.ItemsDestinationCount(), 1);

            _item2.SetDestination(account);
            Assert.AreEqual(account.ItemsDestinationCount(), 2);

            var account2 = new Account
            {
                Name = "Test Account",
                IsValid = true,

            };
            account2.setType(_accountType1);
            account2.setCategory(_accountCategory);

            Assert.AreEqual(account2.ItemsDestinationCount(), 0);
            _item.SetDestination(account2);
            Assert.AreEqual(account.ItemsDestinationCount(), 1);
            Assert.AreEqual(account2.ItemsDestinationCount(), 1);
        }
Exemplo n.º 5
0
        public void List_of_categories_updated_correctly()
        {
            AccountCategory accountCategory1 = new AccountCategory
            {
                Name = "Other",
                Colour = "Orange",
                IsValid = true,
            };
            AccountCategory accountCategory2 = new AccountCategory
            {
                Name = "Other2",
                Colour = "Blue",
                IsValid = true,
            };

            var account = new Account
            {
                IsValid = true,
                Name = "Test Account",
            };

            Assert.AreEqual(0, accountCategory1.AccountCount());
            Assert.AreEqual(0, accountCategory2.AccountCount());
            account.setCategory(accountCategory1);

            Assert.AreEqual(1, accountCategory1.AccountCount());
            Assert.AreEqual(0, accountCategory2.AccountCount());

            account.setCategory(accountCategory2);

            Assert.AreEqual(0, accountCategory1.AccountCount());
            Assert.AreEqual(1, accountCategory2.AccountCount());
        }
Exemplo n.º 6
0
        private static void ImportAccounts(OleDbConnection dbConnection,
            IDictionary<string, Account> accounts,
            IDictionary<string, AccountType> accountTypes,
            IDictionary<string, AccountCategory> accountCategories)
        {
            OleDbDataAdapter dataAdapter;
            DataSet dataSet = new DataSet();

            dataAdapter = new OleDbDataAdapter("SELECT * FROM [Accounts$]", dbConnection);

            dataAdapter.Fill(dataSet);

            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                Account account = new Account
                {
                    Name = row["Name"].ToString(),
                    IsValid = bool.Parse(row["IsValid"].ToString()),
                };
                account.setCategory(accountCategories[row["Category Name"].ToString()]);
                account.setType(accountTypes[row["Type Name"].ToString()]);

                accounts.Add(account.Name, account);
            }
        }
Exemplo n.º 7
0
        public void Can_create_new_accountCategory()
        {
            Account account;

            account = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };

            var accountCategory = new AccountCategory {
                Name = "Other",
                Colour = "Orange",
                IsValid = true,
            };

            account.setCategory(accountCategory);

            Assert.AreEqual(accountCategory.Id, Guid.Empty);
            Assert.AreEqual(account.Category, accountCategory);
        }
Exemplo n.º 8
0
        private void CreateInitialData()
        {
            _accountType1 = new AccountType
            {
                Name = "Asset",
                IsDestination = true,
                IsSource = true,
                IsValid = true,
            };
            _accountType2 = new AccountType
            {
                Name = "Expense",
                IsDestination = true,
                IsSource = true,
                IsValid = true,
            };
            _accountType3 = new AccountType
            {
                Name = "Income",
                IsDestination = false,
                IsSource = true,
                IsValid = true,
            };

            _accountType4 = new AccountType
            {
                Name = "Fail test",
                IsDestination = true,
                IsSource = false,
                IsValid = true,
            };

            _accountCategory = new AccountCategory
            {
                Name = "Other",
                Colour = "Orange",
                IsValid = true,
            };
            _account1 = new Account
            {
                Name = "Bank Account",
                IsValid = true
            };
            _account1.setType(_accountType1);
            _account1.setCategory(_accountCategory);

            _account2 = new Account
            {
                Name = "Food",
                IsValid = true
            };
            _account2.setType(_accountType2);
            _account2.setCategory(_accountCategory);

            _account3 = new Account
            {
                Name = "Pay",
                IsValid = true
            };
            _account3.setType(_accountType3);
            _account3.setCategory(_accountCategory);

            _account4 = new Account
            {
                Name = "Test",
                IsValid = true,
            };
            _account4.setType(_accountType4);
            _account4.setCategory(_accountCategory);

            DateTime tempDate = new DateTime(2009, 2, 5);
            _transaction = new Transaction
            {
                Date = tempDate,
                Description = "Some payment",
                IsVerified = false,
            };
            _item1 = new Item
            {
                Value = 123.0M,
                IsVerified = true,
                Description = "Payment 1",
            };
            _item1.SetTransaction(_transaction);
            _item1.SetSource(_account1);
            _item1.SetDestination(_account2);

            _item2 = new Item
            {
                Value = 456.0M,
                IsVerified = true,
                Description = "Payment 2",
            };
            _item2.SetTransaction(_transaction);
            _item2.SetSource(_account2);
            _item2.SetDestination(_account1);

            using (ISession session = SessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(_accountType1);
                session.Save(_accountType2);
                session.Save(_accountType3);
                session.Save(_accountType4);
                session.Save(_accountCategory);
                session.Save(_account1);
                session.Save(_account2);
                session.Save(_account3);
                session.Save(_account4);
                session.Save(_transaction);
                session.Save(_item1);
                session.Save(_item2);
                transaction.Commit();
            }
        }
        private void CreateInitialData()
        {
            _accountCategory = new AccountCategory { Name = "Test", Colour = "Green", IsValid = true };
            _accountCategory2 = new AccountCategory { Name = "SomethingElse", Colour = "Green", IsValid = true };

            _accountType1 = new AccountType { Name = "Asset", IsDestination = true, IsSource = true, IsValid = true };
            _accountType2 = new AccountType { Name = "SourceOnly", IsDestination = false, IsSource = true, IsValid = true };
            _accountType3 = new AccountType { Name = "DestinationOnly", IsDestination = true, IsSource = false, IsValid = true };
            _account1 = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };
            _account1.setType(_accountType1);
            _account1.setCategory(_accountCategory);

            _account2 = new Account
            {
                Name = "Savings",
                IsValid = true,
            };
            _account2.setType(_accountType1);
            _account2.setCategory(_accountCategory);

            _account3 = new Account
            {
                Name = "SourceOnly",
                IsValid = true,
            };
            _account3.setType(_accountType2);
            _account3.setCategory(_accountCategory);

            _account4 = new Account
            {
                Name = "DestinationOnly",
                IsValid = true,
            };
            _account4.setType(_accountType3);
            _account4.setCategory(_accountCategory);

            using (ISession session = SessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(_accountType1);
                session.Save(_accountType2);
                session.Save(_accountType3);
                session.Save(_accountCategory);
                session.Save(_accountCategory2);
                session.Save(_account1);
                session.Save(_account2);
                session.Save(_account3);
                session.Save(_account4);
                transaction.Commit();
            }
        }
Exemplo n.º 10
0
        public void Change_account_category()
        {
            var account = new Account { Name = "Credit Card", IsValid = true };
            account.setType(_accountType1);
            account.setCategory(_accountCategory);
            account.setCategory(_accountCategory2);

            IAccountRepository Arepository = new AccountRepository();

            Arepository.Add(account);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<Account>(account.Id);

                Assert.IsTrue(IsInCollection(account, account.Category.Accounts));
                Assert.IsFalse(IsInCollection(account, _accountCategory.Accounts));

            }
        }
Exemplo n.º 11
0
 public void Can_not_update_a_non_existing_account()
 {
     var account = new Account
     {
         Name = "Test Account",
         IsValid = true,
     };
     account.setType(_accountType1);
     account.setCategory(_accountCategory);
     IAccountRepository repository = new AccountRepository();
     repository.Update(account);
 }
Exemplo n.º 12
0
        public void TestFixtureSetUp()
        {
            _accountType1 = new AccountType
            {
                Name = "Asset",
                IsDestination = true,
                IsSource = true,
                IsValid = true,
            };
            _accountType2 = new AccountType
            {
                Name = "Expense",
                IsDestination = true,
                IsSource = true,
                IsValid = true,
            };
            _accountType3 = new AccountType
            {
                Name = "NotSource",
                IsDestination = true,
                IsSource = false,
                IsValid = true,
            };
            _accountType4 = new AccountType
            {
                Name = "NotDestination",
                IsDestination = false,
                IsSource = true,
                IsValid = true,
            };
            _accountCategory = new AccountCategory
            {
                Name = "Other",
                Colour = "Orange",
                IsValid = true,
            };
            _account1 = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };
            _account1.setType(_accountType1);
            _account1.setCategory(_accountCategory);

            _account2 = new Account
            {
                Name = "Food",
                IsValid = true,
            };
            _account2.setType(_accountType2);
            _account2.setCategory(_accountCategory);

            _account3 = new Account
            {
                Name = "Not Source",
                IsValid = true,
            };
            _account3.setType(_accountType3);
            _account3.setCategory(_accountCategory);

            _account4 = new Account
            {
                Name = "Not Destination",
                IsValid = true,
            };
            _account4.setType(_accountType4);
            _account4.setCategory(_accountCategory);

            DateTime tempDate = new DateTime(2009, 2, 5);
            _transaction1 = new Transaction
            {
                Date = tempDate,
                Description = "Some payment",
                IsVerified = false,
            };

            _transaction2 = new Transaction
            {
                Date = tempDate,
                Description = "Some other payment",
                IsVerified = true,
            };

            _transaction3 = new Transaction
            {
                Date = tempDate,
                Description = "A further payment",
                IsVerified = true,
            };
        }
Exemplo n.º 13
0
        public void SourceUpdatedIfItemMovedLazily()
        {
            Account account1;
            Account account2;

            account1 = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };
            account1.setType(_accountType1);
            account1.setCategory(_accountCategory);

            account2 = new Account
            {
                Name = "Food",
                IsValid = true,
            };
            account2.setType(_accountType2);
            account2.setCategory(_accountCategory);

            var item = new Item
            {
                Value = 99.99M,
                Description = "Move Test",
                IsVerified = true,
            };

            item.SetSourceLazy(account2);
            Assert.AreEqual(item.Source, account2);
            Assert.AreNotEqual(item.Source, account1);

            item.SetSourceLazy(account1);
            Assert.AreEqual(item.Source, account1);
            Assert.AreNotEqual(item.Source, account2);
        }
Exemplo n.º 14
0
        public void DestinationUpdatedIfItemMovedLazily()
        {
            Account account1;
            Account account3;

            account1 = new Account
            {
                Name = "Bank Account",
                IsValid = true,
            };
            account1.setType(_accountType1);
            account1.setCategory(_accountCategory);

            account3 = new Account
            {
                Name = "Not Source",
                IsValid = true,
            };
            account3.setType(_accountType3);
            account3.setCategory(_accountCategory);

            var item = new Item
            {
                Value = 99.99M,
                Description = "Move Test",
                IsVerified = true,
            };

            item.SetDestinationLazy(account3);
            Assert.AreEqual(item.Destination, account3);
            Assert.AreNotEqual(item.Destination, account1);

            item.SetDestinationLazy(account1);
            Assert.AreEqual(item.Destination, account1);
            Assert.AreNotEqual(item.Destination, account3);
        }