示例#1
0
        public void UpdateTransactionTest()
        {
            ITransactionFactory transactionFactory = new RegularTransactionFactory();
            var accountStorage  = new SqLiteAccountStorage(new RegularAccountFactory());
            var categoryStorage = new SqLiteCategoryStorage(new RegularCategoryFactory());
            var storage         = new SqLiteTransactionStorage(transactionFactory, accountStorage, categoryStorage);

            categoryStorage.DeleteAllData();
            accountStorage.DeleteAllData();
            storage.DeleteAllData();
            var transaction       = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var childTransaction  = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var childTransaction1 = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var newTransaction    = storage.CreateTransaction(transaction);

            storage.AddChildTransaction(newTransaction, storage.CreateTransaction(childTransaction));
            storage.AddChildTransaction(newTransaction, storage.CreateTransaction(childTransaction1));
            childTransaction1.Name  = "New Name";
            childTransaction1.Total = 515.03m;


            storage.UpdateTransaction(childTransaction1);


            var firstTransaction = storage.GetAllTransactions().First(x => x.Id == childTransaction1.Id);

            Assert.AreEqual(childTransaction1.Name, firstTransaction.Name);
            Assert.AreEqual(childTransaction1.Category.Id, firstTransaction.Category.Id);
            Assert.AreEqual(childTransaction1.Account.Id, firstTransaction.Account.Id);
            Assert.AreEqual(childTransaction1.Total, firstTransaction.Total);
        }
示例#2
0
        public void DeleteComplexTransactionTest()
        {
            ITransactionFactory transactionFactory = new RegularTransactionFactory();
            var accountStorage  = new SqLiteAccountStorage(new RegularAccountFactory());
            var categoryStorage = new SqLiteCategoryStorage(new RegularCategoryFactory());
            var storage         = new SqLiteTransactionStorage(transactionFactory, accountStorage, categoryStorage);

            categoryStorage.DeleteAllData();
            accountStorage.DeleteAllData();
            storage.DeleteAllData();
            var transaction       = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var childTransaction  = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var childTransaction1 = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var newTransaction    = storage.CreateTransaction(transaction);

            storage.AddChildTransaction(newTransaction, storage.CreateTransaction(childTransaction));
            storage.AddChildTransaction(newTransaction, storage.CreateTransaction(childTransaction1));



            storage.DeleteTransaction(newTransaction);


            var numberOfTransactions = storage.GetAllTransactions().Count();


            Assert.AreEqual(0, numberOfTransactions);
        }
示例#3
0
        public void CreateComplexTransactionTest()
        {
            var accountStorage     = new SqLiteAccountStorage(new RegularAccountFactory());
            var categoryStorage    = new SqLiteCategoryStorage(new RegularCategoryFactory());
            var transactionFactory = new RegularTransactionFactory();
            var storage            = new SqLiteTransactionStorage(transactionFactory, accountStorage, categoryStorage);

            categoryStorage.DeleteAllData();
            accountStorage.DeleteAllData();
            storage.DeleteAllData();
            var transaction       = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var childTransaction  = CreateTransaction(accountStorage, categoryStorage, transactionFactory);
            var childTransaction1 = CreateTransaction(accountStorage, categoryStorage, transactionFactory);

            var newTransaction = storage.CreateTransaction(transaction);

            storage.AddChildTransaction(newTransaction, storage.CreateTransaction(childTransaction));
            storage.AddChildTransaction(newTransaction, storage.CreateTransaction(childTransaction1));


            var complexTransaction = storage.GetAllTransactions().FirstOrDefault(x => x.IsComplexTransaction);

            Assert.AreEqual(transaction.Name, complexTransaction?.Name);
            Assert.AreEqual(transaction.Category.Id, complexTransaction?.Category?.Id);
            Assert.AreEqual(transaction.Account.Id, complexTransaction?.Account?.Id);
            Assert.AreEqual(426.00m, complexTransaction?.Total);
        }