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));
            }
        }
Beispiel #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);
 }
        public void Can_create_new_transaction()
        {
            var item = new Item
            {
                Value = 567.78M,
                Description = "Add Test",
                IsVerified = true,
            };

            var transaction = new Transaction {
                BusinessKey = 1,
                Date = new DateTime(2009, 11, 15),
                Description = "Test Transaction",
                IsVerified = true,

            };
            item.SetTransaction(transaction);

            Assert.IsNotNull(transaction);
            Assert.AreEqual(transaction.Id, Guid.Empty);
            Assert.AreEqual(transaction.ItemCount(), 1);
        }
Beispiel #4
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);
            }
        }
        public void ItemCountReturnsCorrectValues()
        {
            var item = new Item
            {
                Value = 567.78M,
                Description = "Add Test",
                IsVerified = true,
            };

            var item2 = new Item
            {
                Value = 667.78M,
                Description = "Add Test 2",
                IsVerified = false,
            };
            var transaction = new Transaction
            {
                BusinessKey = 1,
                Date = new DateTime(2009, 11, 15),
                Description = "Test Transaction",
                IsVerified = true,

            };
            Assert.AreEqual(transaction.ItemCount(), 0);

            item.SetTransaction(transaction);
            Assert.AreEqual(transaction.ItemCount(), 1);

            item.SetTransaction(transaction);
            Assert.AreEqual(transaction.ItemCount(), 1);

            item2.SetTransaction(transaction);
            Assert.AreEqual(transaction.ItemCount(), 2);

            var transaction2 = new Transaction
            {
                BusinessKey = 1,
                Date = new DateTime(2009, 11, 16),
                Description = "Test Transaction2",
                IsVerified = true,

            };
            Assert.AreEqual(transaction2.ItemCount(), 0);
            item.SetTransaction(transaction2);
            Assert.AreEqual(transaction.ItemCount(), 1);
            Assert.AreEqual(transaction2.ItemCount(), 1);
        }
        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();
            }
        }
Beispiel #7
0
 public void Transaction_TransactionDate()
 {
     var item = new Item
     {
         Value = 99.99M,
         Description = "Move Test",
         IsVerified = true,
     };
     item.SetTransaction(_transaction1);
     Assert.AreEqual(item.TransactionDate, "05 February 2009");
 }
Beispiel #8
0
        public void Transaction_TVerfied()
        {
            var item = new Item
            {
                Value = 99.99M,
                Description = "Move Test",
                IsVerified = true,
            };
            item.SetTransaction(_transaction1);
            Assert.AreEqual(item.TVerified, false);

            item.TVerified = true;
            Assert.AreEqual(item.TVerified, true);
            Assert.AreEqual(_transaction1.IsVerified, true);
        }
Beispiel #9
0
        public void Transaction_desc_works()
        {
            var item = new Item
            {
                Value = 99.99M,
                Description = "Move Test",
                IsVerified = true,
            };
            Assert.AreEqual("Move Test", item.Description);
            Assert.AreEqual("Move Test", item.TransactionDesc);

            item.SetTransaction(_transaction1);
            Assert.AreEqual("Some payment", _transaction1.Description);
            Assert.AreEqual("Some payment: Move Test", item.TransactionDesc);

            _transaction1.Description = "";
            Assert.AreEqual("Move Test", item.TransactionDesc);
        }
Beispiel #10
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());
        }
Beispiel #11
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);
        }
Beispiel #12
0
 public void Cannot_move_money_within_the_same_account_lazily()
 {
     var item = new Item
     {
         Value = 567.78M,
         Description = "Add Test",
         IsVerified = true,
     };
     item.SetTransaction(_transaction1);
     item.SetSourceLazy(_account1);
     item.SetDestinationLazy(_account1);
 }
Beispiel #13
0
 public void Cannot_move_money_into_source_only_account_lazily()
 {
     var item = new Item
     {
         Value = 88.01M,
         Description = "Add Test",
         IsVerified = true,
     };
     item.SetTransaction(_transaction1);
     item.SetSourceLazy(_account1);
     item.SetDestinationLazy(_account4);
 }