public void Can_delete_existing_accountType()
        {
            var accountType = _accountTypes[0];
            IAccountTypeRepository repository = new AccountTypeRepository();
            repository.Remove(accountType);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<AccountType>(accountType.Id);
                Assert.IsNull(fromDb);
            }
        }
        public void Can_get_all_existing_account_Types()
        {
            IAccountTypeRepository repository = new AccountTypeRepository();
            var fromDb = repository.GetAll();

            Assert.AreEqual(fromDb.Count, 7);
            Assert.IsTrue(IsInCollection(_accountTypes[0], fromDb));
            Assert.IsTrue(IsInCollection(_accountTypes[1], fromDb));
            Assert.IsTrue(IsInCollection(_accountTypes[2], fromDb));
            Assert.IsTrue(IsInCollection(_accountTypes[3], fromDb));
            Assert.IsTrue(IsInCollection(_accountTypes[4], fromDb));
            Assert.IsTrue(IsInCollection(_accountTypes[5], fromDb));
            Assert.IsTrue(IsInCollection(_accountTypes[6], fromDb));
        }
        public void Can_add_new_accountType()
        {
            var accountType = new AccountType { Name = "TestAccountType", IsSource = true, IsDestination = true, IsValid = true };
            IAccountTypeRepository repository = new AccountTypeRepository();
            repository.Add(accountType);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<AccountType>(accountType.Id);
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(accountType, fromDb);
                Assert.AreEqual(accountType.Name, fromDb.Name);
                Assert.AreEqual(accountType.IsSource, fromDb.IsSource);
                Assert.AreEqual(accountType.IsDestination, fromDb.IsDestination);
                Assert.AreEqual(accountType.IsValid, fromDb.IsValid);
            }
        }
Example #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();
        }
Example #5
0
        private static void ExportAccountTypes(OleDbConnection dbConnection)
        {
            OleDbCommand createTable = new OleDbCommand("CREATE TABLE `AccountTypes` (" +
                "`Name` LongText, " +
                "`IsSource` LongText, " +
                "`IsDestination` LongText, " +
                "`IsValid` LongText " +
                ")", dbConnection);
            createTable.ExecuteNonQuery();

            AccountTypeRepository repository = new AccountTypeRepository();

            var accountTypes = repository.GetAll();

            foreach (AccountType a in accountTypes)
            {
                string insertStatement = "INSERT INTO [AccountTypes] ([Name], [IsSource], [IsDestination], [IsValid]) VALUES ('" +
                    a.Name + "', '" +
                    a.IsSource + "', '" +
                    a.IsDestination + "', '" +
                    a.IsValid + "')";

                OleDbCommand insert = new OleDbCommand(insertStatement, dbConnection);
                insert.ExecuteNonQuery();
            }
        }
        public void Can_get_existing_accountType_by_id()
        {
            IAccountTypeRepository repository = new AccountTypeRepository();
            var fromDb = repository.GetById(_accountTypes[1].Id);

            Assert.IsNotNull(fromDb);
            Assert.AreNotSame(_accountTypes[1], fromDb);
            Assert.AreEqual(_accountTypes[1].Name, fromDb.Name);
        }
        public void Can_update_existing_accountType()
        {
            var accountType = _accountTypes[0];
            accountType.Name = "ModifiedAccountType";
            IAccountTypeRepository repository = new AccountTypeRepository();
            repository.Update(accountType);

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