public void Cannot_get_non_existing_item_for_single_date()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetByDate(_item1.TransactionId.Date.AddDays(-1D));

            Assert.AreEqual(0, fromDb.Count);
        }
        public void Can_add_new_item()
        {
            var item = new Item
            {
                Value = 0.01M,
                Description = "Add Test",
                IsVerified = true,
            };
            item.SetTransaction(_transaction);
            item.SetSource(_account1);
            item.SetDestination(_account2);

            IItemRepository repository = new ItemRepository();
            repository.Add(item);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<Item>(item.Id);
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(item, fromDb);
                Assert.AreEqual(item.Value, fromDb.Value);
                Assert.AreEqual(item.Description, fromDb.Description);
                Assert.AreEqual(item.Destination.Id, fromDb.Destination.Id);
                Assert.AreEqual(item.Source.Id, fromDb.Source.Id);
                Assert.AreEqual(item.IsVerified, fromDb.IsVerified);
                Assert.AreEqual(item.TransactionId.Id, fromDb.TransactionId.Id);

                Assert.IsTrue(IsInCollection(item, item.TransactionId.Items));
                Assert.IsTrue(IsInCollection(item, item.Source.ItemsSource));
                Assert.IsTrue(IsInCollection(item, item.Destination.ItemsDestination));
            }
        }
        public void Cannot_get_existing_item_by_date_range()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetByDate(_item1.TransactionId.Date.AddDays(1D), _item1.TransactionId.Date.AddDays(2D));

            Assert.AreEqual(0, fromDb.Count);
            Assert.IsFalse(IsInCollection(_item1, fromDb));
            Assert.IsFalse(IsInCollection(_item2, fromDb));
        }
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 ExportItems(OleDbConnection dbConnection)
        {
            OleDbCommand createTable = new OleDbCommand("CREATE TABLE `Items` (" +
                "`TransactionKey` LongText, " +
                "`Source` LongText, " +
                "`Destination` LongText, " +
                "`Value` LongText, " +
                "`Description` LongText, " +
                "`IsVerified` LongText" +
                ")", dbConnection);
            createTable.ExecuteNonQuery();

            ItemRepository repository = new ItemRepository();

            var items = repository.GetAll();

            foreach (Item i in items)
            {

                if (i.Description != null)
                {
                    i.Description = i.Description.Replace("'", "''");
                }

                string insertStatement = "INSERT INTO [Items] ([TransactionKey], [Source], [Destination], [Value], [Description], [IsVerified]) VALUES ('" +
                    i.TransactionId.BusinessKey + "', '" +
                    i.Source.Name + "', '" +
                    i.Destination.Name + "', '" +
                    i.Value.ToString() + "', '" +
                    i.Description + "', '" +
                    i.IsVerified + "')";

                OleDbCommand insert = new OleDbCommand(insertStatement, dbConnection);
                insert.ExecuteNonQuery();

            }
        }
        public void Can_delete_existing_item()
        {
            var item = _item1;
            IItemRepository repository = new ItemRepository();
            repository.Remove(item);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<Item>(item.Id);
                Assert.IsNull(fromDb);
            }
        }
        public void Can_update_existing_item()
        {
            var item = _item1;
            item.Description = "Kirsch Sweets";
            item.IsVerified = false;
            IItemRepository repository = new ItemRepository();
            repository.Update(item);

            using (ISession session = SessionFactory.OpenSession())
            {
                var fromDb = session.Get<Item>(item.Id);
                Assert.AreEqual(item.Description, fromDb.Description);
                Assert.AreEqual(item.IsVerified, fromDb.IsVerified);
            }
        }
        public void Can_get_existing_item_by_single_date()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetByDate(_item1.TransactionId.Date);

            Assert.AreEqual(2, fromDb.Count);
            Assert.IsTrue(IsInCollection(_item1, fromDb));
            Assert.IsTrue(IsInCollection(_item2, fromDb));
        }
        public void Can_get_existing_item_by_id()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetById(_item1.Id);

            using (ISession session = SessionFactory.OpenSession())
            {
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(_item1, fromDb);
                Assert.AreEqual(_item1.Value, fromDb.Value);
                Assert.AreEqual(_item1.Description, fromDb.Description);
                Assert.AreEqual(_item1.Destination.Id, fromDb.Destination.Id);
                Assert.AreEqual(_item1.Source.Id, fromDb.Source.Id);
                Assert.AreEqual(_item1.IsVerified, fromDb.IsVerified);
                Assert.AreEqual(_item1.TransactionId.Id, fromDb.TransactionId.Id);
                Assert.AreEqual(_item1.TransactionId.Date, fromDb.TransactionId.Date);
                Assert.AreEqual(_item1.Destination.Name, fromDb.Destination.Name);
                Assert.AreEqual(_item1.Source.Name, fromDb.Source.Name);
                Assert.AreEqual(_item1.Destination.Type.Name, fromDb.Destination.Type.Name);
                Assert.AreEqual(_item1.Source.Type.Name, fromDb.Source.Type.Name);
            }
        }
        public void Can_get_existing_items_by_transaction()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetByTransaction(_transaction);

            Assert.AreEqual(2, fromDb.Count);
            Assert.IsTrue(IsInCollection(_item1, fromDb));
            Assert.IsTrue(IsInCollection(_item2, fromDb));
        }
        public void Can_get_existing_items_by_sourceAccount()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetBySourceAccount(_account1);

            Assert.AreEqual(1, fromDb.Count);
            Assert.IsTrue(IsInCollection(_item1, fromDb));
            Assert.IsFalse(IsInCollection(_item2, fromDb));
        }
        public void Can_get_all()
        {
            IItemRepository repository = new ItemRepository();
            var fromDb = repository.GetAll();

            Assert.AreEqual(2, fromDb.Count);
            Assert.IsTrue(IsInCollection(_item1, fromDb));
            Assert.IsTrue(IsInCollection(_item2, fromDb));
        }