public void Can_get_all()
        {
            IAccountCategoryRepository repository = new AccountCategoryRepository();
            var fromDb = repository.GetAll();

            Assert.AreEqual(4, fromDb.Count);
            Assert.IsTrue(IsInCollection(_accountCategories[0], fromDb));
            Assert.IsTrue(IsInCollection(_accountCategories[1], fromDb));
            Assert.IsTrue(IsInCollection(_accountCategories[2], fromDb));
            Assert.IsTrue(IsInCollection(_accountCategories[3], fromDb));
        }
        public void Can_delete_existing_accountCategory()
        {
            var accountCategory = _accountCategories[0];
            IAccountCategoryRepository repository = new AccountCategoryRepository();
            repository.Remove(accountCategory);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<AccountCategory>(accountCategory.Id);
                Assert.IsNull(fromDb);
            }
        }
        public void Can_add_new_accountCategory()
        {
            var accountCategory = new AccountCategory { Name = "Savings", Colour = "Yellow", IsValid = true };
            IAccountCategoryRepository repository = new AccountCategoryRepository();
            repository.Add(accountCategory);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<AccountCategory>(accountCategory.Id);
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(accountCategory, fromDb);
                Assert.AreEqual(accountCategory.Name, fromDb.Name);
                Assert.AreEqual(accountCategory.Colour, fromDb.Colour);
                Assert.AreEqual(accountCategory.IsValid, fromDb.IsValid);
            }
        }
示例#4
0
        public static void ImportFromExcelFile(string filename)
        {
            IDictionary<string, AccountType> accountTypes = new Dictionary<string, AccountType>();
            IDictionary<string, AccountCategory> accountCategories = new Dictionary<string, AccountCategory>();
            IDictionary<string, Account> accounts = new Dictionary<string, Account>();
            Iesi.Collections.Generic.ISet<Item> items = new HashedSet<Item>();
            IDictionary<int, Transaction> transactions = new Dictionary<int, Transaction>();

            OleDbConnection excelConnection;

            excelConnection = new OleDbConnection(
                "Provider=Microsoft.ACE.OLEDB.12.0; " +
                "Data Source=" + filename + "; " +
                "Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\"");

            excelConnection.Open();

            RecreateDatabase();
            ImportAccountTypes(excelConnection, accountTypes);
            ImportAccountCategories(excelConnection, accountCategories);
            ImportAccounts(excelConnection, accounts, accountTypes, accountCategories);
            ImportTransactions(excelConnection, transactions);
            ImportItems(excelConnection, items, accounts, transactions);

            AccountTypeRepository atr = new AccountTypeRepository();
            AccountCategoryRepository acr = new AccountCategoryRepository();
            AccountRepository ar = new AccountRepository();
            TransactionRepository tr = new TransactionRepository();
            ItemRepository ir = new ItemRepository();

            foreach (AccountType at in accountTypes.Values) atr.Add(at);
            foreach (AccountCategory ac in accountCategories.Values) acr.Add(ac);
            foreach (Account a in accounts.Values) ar.Add(a);
            foreach (Transaction t in transactions.Values) tr.Add(t);
            foreach (Item i in items) ir.Add(i);

            excelConnection.Close();
        }
示例#5
0
        private static void ExportAccountCategories(OleDbConnection dbConnection)
        {
            OleDbCommand createTable = new OleDbCommand("CREATE TABLE `AccountCategories` (" +
                "`Name` LongText, " +
                "`Colour` LongText, " +
                "`IsValid` LongText" +
                ")", dbConnection);
            createTable.ExecuteNonQuery();

            AccountCategoryRepository repository = new AccountCategoryRepository();

            var accountCategories = repository.GetAll();

            foreach (AccountCategory a in accountCategories)
            {
                string insertStatement = "INSERT INTO [AccountCategories] ([Name], [Colour], [IsValid]) VALUES ('" +
                    a.Name + "', '" +
                    a.Colour + "', '" +
                    a.IsValid + "')";

                OleDbCommand insert = new OleDbCommand(insertStatement, dbConnection);
                insert.ExecuteNonQuery();
            }
        }
        public void Can_get_existing_accountCategory_by_name()
        {
            IAccountCategoryRepository repository = new AccountCategoryRepository();
            var fromDb = repository.GetByName(_accountCategories[2].Name);

            Assert.IsNotNull(fromDb);
            Assert.AreNotSame(_accountCategories[2], fromDb);
            Assert.AreEqual(_accountCategories[2].Id, fromDb.Id);
        }
        public void Can_update_existing_accountCategory()
        {
            var accountCategory = _accountCategories[0];
            accountCategory.Name = "ModifiedAccountCategory";
            IAccountCategoryRepository repository = new AccountCategoryRepository();
            repository.Update(accountCategory);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<AccountCategory>(accountCategory.Id);
                Assert.AreEqual(accountCategory.Name, fromDb.Name);
            }
        }