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));
            }
        }
示例#2
0
 public void Cannot_move_money_from_destination_only_account()
 {
     var item = new Item
     {
         Value = 99.01M,
         Description = "Add Test",
         IsVerified = true,
     };
     item.SetTransaction(_transaction1);
     item.SetSource(_account3);
     item.SetDestination(_account1);
 }
示例#3
0
        private static void ImportItems(OleDbConnection dbConnection,
            Iesi.Collections.Generic.ISet<Item> items,
            IDictionary<string, Account> accounts,
            IDictionary<int, Transaction> transactions)
        {
            OleDbDataAdapter dataAdapter;
            DataSet dataSet = new DataSet();

            dataAdapter = new OleDbDataAdapter("SELECT * FROM [Items$]", dbConnection);
            dataAdapter.Fill(dataSet);

            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                Account source = accounts[row["Source"].ToString()];
                Account destination = accounts[row["Destination"].ToString()];

                int tranKey = Int32.Parse(row["TransactionKey"].ToString());
                Decimal value = Decimal.Parse(row["Value"].ToString());

                Transaction transaction = transactions[tranKey];

                Item item = new Item
                {
                    Description = row["Description"].ToString(),
                    Value = value,
                    IsVerified = bool.Parse(row["IsVerified"].ToString()),
                };
                item.SetTransaction(transaction);
                item.SetSource(source);
                item.SetDestination(destination);

                items.Add(item);
            }
        }
        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();
            }
        }
示例#5
0
        public void TransactionUpdatedIfItemMoved()
        {
            var item = new Item
            {
                Value = 99.99M,
                Description = "Move Test",
                IsVerified = true,
            };
            item.SetTransaction(_transaction3);
            item.SetDestination(_account1);
            item.SetSource(_account2);
            Assert.AreEqual(item.TransactionId, _transaction3);
            Assert.AreNotEqual(item.TransactionId, _transaction2);
            Assert.AreEqual(1, _transaction3.ItemCount());
            Assert.AreEqual(0, _transaction2.ItemCount());

            item.SetTransaction(_transaction2);
            Assert.AreEqual(item.TransactionId, _transaction2);
            Assert.AreNotEqual(item.TransactionId, _transaction3);
            Assert.AreEqual(0, _transaction3.ItemCount());
            Assert.AreEqual(1, _transaction2.ItemCount());
        }
示例#6
0
        public void SourceUpdatedIfItemMoved()
        {
            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.SetSource(account2);
            Assert.AreEqual(item.Source, account2);
            Assert.AreNotEqual(item.Source, account1);
            Assert.AreEqual(1, account2.ItemsSourceCount());
            Assert.AreEqual(0, account1.ItemsSourceCount());

            item.SetSource(account1);
            Assert.AreEqual(item.Source, account1);
            Assert.AreNotEqual(item.Source, account2);
            Assert.AreEqual(1, account1.ItemsSourceCount());
            Assert.AreEqual(0, account2.ItemsSourceCount());
        }
示例#7
0
 public void Item_SourceName()
 {
     var item = new Item
     {
         Value = 99.99M,
         Description = "Move Test",
         IsVerified = true,
     };
     item.SetSource(_account1);
     Assert.AreEqual(item.SourceName, "Bank Account");
 }
示例#8
0
        public void Can_create_new_item()
        {
            var item = new Item
            {
                Value = 0.01M,
                Description = "Add Test",
                IsVerified = true,
            };
            item.SetTransaction(_transaction1);
            item.SetSource(_account1);
            item.SetDestination(_account2);

            Assert.IsNotNull(item);
            Assert.AreEqual(item.Id, Guid.Empty);
            Assert.AreEqual(item.Source.Id, Guid.Empty);
            Assert.AreEqual(item.Source.Category.Id, Guid.Empty);
            Assert.AreEqual(item.Source.Type.Id, Guid.Empty);
            Assert.AreEqual(item.Destination.Id, Guid.Empty);
            Assert.AreEqual(item.Destination.Category.Id, Guid.Empty);
            Assert.AreEqual(item.Destination.Type.Id, Guid.Empty);
            Assert.AreEqual(item.TransactionId.Id, Guid.Empty);

            Assert.AreEqual(item.Description, "Add Test");
            Assert.AreEqual(item.Destination, _account2);
            Assert.AreEqual(item.IsVerified, true);
            Assert.AreEqual(item.Source, _account1);
            Assert.AreEqual(item.TransactionId, _transaction1);
            Assert.AreEqual(item.Value, 0.01M);
            Assert.AreEqual(item.Destination.Category, _account2.Category);
            Assert.AreEqual(item.Destination.Category.Colour, _account2.Category.Colour);
            Assert.AreEqual(item.Destination.Category.IsValid, _account2.Category.IsValid);
            Assert.AreEqual(item.Destination.Category.Name, _account2.Category.Name);
            Assert.AreEqual(item.Destination.IsValid, _account2.IsValid);
            Assert.AreEqual(item.Destination.Name, _account2.Name);
            Assert.AreEqual(item.Destination.Type, _account2.Type);
            Assert.AreEqual(item.Destination.Type.IsDestination, _account2.Type.IsDestination);
            Assert.AreEqual(item.Destination.Type.IsSource, _account2.Type.IsSource);
            Assert.AreEqual(item.Destination.Type.IsValid, _account2.Type.IsValid);
            Assert.AreEqual(item.Destination.Type.Name, _account2.Type.Name);
            Assert.AreEqual(item.Source.Category, _account1.Category);
            Assert.AreEqual(item.Source.Category.Colour, _account1.Category.Colour);
            Assert.AreEqual(item.Source.Category.IsValid, _account1.IsValid);
            Assert.AreEqual(item.Source.Category.Name, _account1.Category.Name);
            Assert.AreEqual(item.Source.IsValid, _account1.IsValid);
            Assert.AreEqual(item.Source.Name, _account1.Name);
            Assert.AreEqual(item.Source.Type, _account1.Type);
            Assert.AreEqual(item.Source.Type.IsDestination, _account1.Type.IsDestination);
            Assert.AreEqual(item.Source.Type.IsSource, _account1.Type.IsSource);
            Assert.AreEqual(item.Source.Type.IsValid, _account1.Type.IsValid);
            Assert.AreEqual(item.Source.Type.Name, _account1.Type.Name);
        }
示例#9
0
 public void Cannot_move_money_within_the_same_account2()
 {
     var item = new Item
     {
         Value = 567.78M,
         Description = "Add Test",
         IsVerified = true,
     };
     item.SetTransaction(_transaction1);
     item.SetDestination(_account1);
     item.SetSource(_account1);
 }