public void RecurringTransactionRepository_Update()
        {
            var dbHelper = new DbHelper(new SQLitePlatformWinRT(), new TestDatabasePath());

            using (var db = dbHelper.GetSqlConnection())
            {
                db.DeleteAll<RecurringTransaction>();
            }

            var repository = new RecurringTransactionRepository(new RecurringTransactionDataAccess(dbHelper));

            var account = new Account
            {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction
            {
                ChargedAccount = account,
                Amount = 20,
                AmountWithoutExchange = 20
            };

            repository.Save(transaction);
            Assert.AreEqual(1, repository.Data.Count);
            Assert.AreSame(transaction, repository.Data[0]);

            transaction.Amount = 789;

            repository.Save(transaction);

            Assert.AreEqual(1, repository.Data.Count);
            Assert.AreEqual(789, repository.Data[0].Amount);
        }
        public void RecurringTransactionRepository_Update()
        {
            using (var db = SqlConnectionFactory.GetSqlConnection()) {
                db.DeleteAll <RecurringTransaction>();
            }

            var repository = new RecurringTransactionRepository(new RecurringTransactionDataAccess());

            var account = new Account {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction {
                ChargedAccount        = account,
                Amount                = 20,
                AmountWithoutExchange = 20
            };


            repository.Save(transaction);
            Assert.AreEqual(1, repository.Data.Count);
            Assert.AreSame(transaction, repository.Data[0]);

            transaction.Amount = 789;

            repository.Save(transaction);

            Assert.AreEqual(1, repository.Data.Count);
            Assert.AreEqual(789, repository.Data[0].Amount);
        }
        public void RecurringTransactionRepository_AddMultipleToCache()
        {
            var recurringTransactionDataAccessMock = new RecurringTransactionDataAccessMock();
            var repository = new RecurringTransactionRepository(recurringTransactionDataAccessMock);

            var account = new Account
            {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction
            {
                ChargedAccount = account,
                Amount = 20,
                AmountWithoutExchange = 20
            };

            var secondTransaction = new RecurringTransaction
            {
                ChargedAccount = account,
                Amount = 60,
                AmountWithoutExchange = 60
            };

            repository.Save(transaction);
            repository.Save(secondTransaction);

            Assert.AreEqual(2, repository.Data.Count);
            Assert.AreSame(transaction, repository.Data[0]);
            Assert.AreSame(secondTransaction, repository.Data[1]);
        }
        public void RecurringTransactionRepository_AddMultipleToCache()
        {
            var repository = new RecurringTransactionRepository(_recurringTransactionDataAccessMock);

            var account = new Account {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction {
                ChargedAccount        = account,
                Amount                = 20,
                AmountWithoutExchange = 20
            };

            var secondTransaction = new RecurringTransaction {
                ChargedAccount        = account,
                Amount                = 60,
                AmountWithoutExchange = 60
            };

            repository.Save(transaction);
            repository.Save(secondTransaction);

            Assert.AreEqual(2, repository.Data.Count);
            Assert.AreSame(transaction, repository.Data[0]);
            Assert.AreSame(secondTransaction, repository.Data[1]);
        }
        public void RecurringTransactionRepository_Delete()
        {
            var recurringTransactionDataAccessMock = new RecurringTransactionDataAccessMock();
            var repository = new RecurringTransactionRepository(recurringTransactionDataAccessMock);

            var account = new Account
            {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction
            {
                ChargedAccount = account,
                Amount = 20,
                AmountWithoutExchange = 20
            };

            repository.Save(transaction);
            Assert.AreSame(transaction, recurringTransactionDataAccessMock.RecurringTransactionTestList[0]);

            repository.Delete(transaction);

            Assert.IsFalse(recurringTransactionDataAccessMock.RecurringTransactionTestList.Any());
            Assert.IsFalse(repository.Data.Any());
        }
        public static async Task UpdateTransaction(FinancialTransaction transaction)
        {
            CheckIfRecurringWasRemoved(transaction);
            await AccountLogic.AddTransactionAmount(transaction);

            TransactionRepository.Save(transaction);

            RecurringTransaction recurringTransaction =
                RecurringTransactionLogic.GetRecurringFromFinancialTransaction(transaction);

            await
            CheckForRecurringTransaction(transaction,
                                         () => RecurringTransactionRepository.Save(recurringTransaction));

            AccountLogic.RefreshRelatedTransactions();
        }
        public void RecurringTransactionRepository_Save()
        {
            var repository = new RecurringTransactionRepository(_recurringTransactionDataAccessMock);

            var account = new Account {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction {
                ChargedAccount        = account,
                Amount                = 20,
                AmountWithoutExchange = 20
            };

            repository.Save(transaction);

            Assert.IsTrue(transaction == _recurringTransactionDataAccessMock.RecurringTransactionTestList[0]);
            Assert.IsTrue(account == _recurringTransactionDataAccessMock.RecurringTransactionTestList[0].ChargedAccount);
        }
        public void TransactionRepository_SaveWithouthAccount()
        {
            try {
                var repository = new RecurringTransactionRepository(_recurringTransactionDataAccessMock);

                var transaction = new RecurringTransaction {
                    Amount = 20,
                    AmountWithoutExchange = 20
                };

                repository.Save(transaction);
            }
            catch (InvalidDataException) {
                return;
            }
            catch (Exception) {
                Assert.Fail("wrong exception.");
            }
            Assert.Fail("No excpetion thrown");
        }
        public static async Task SaveTransaction(FinancialTransaction transaction, bool refreshRelatedList = false,
                                                 bool skipRecurring = false)
        {
            if (transaction.IsRecurring && !skipRecurring)
            {
                RecurringTransaction recurringTransaction =
                    RecurringTransactionLogic.GetRecurringFromFinancialTransaction(transaction);
                RecurringTransactionRepository.Save(recurringTransaction);
                TransactionRepository.Save(transaction);
                transaction.RecurringTransaction = recurringTransaction;
            }

            TransactionRepository.Save(transaction);

            if (refreshRelatedList)
            {
                ServiceLocator.Current.GetInstance <TransactionListViewModel>()
                .SetRelatedTransactions(AccountRepository.Selected);
            }
            await AccountLogic.AddTransactionAmount(transaction);
        }
        public void RecurringTransactionRepository_Delete()
        {
            var repository = new RecurringTransactionRepository(_recurringTransactionDataAccessMock);

            var account = new Account {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction {
                ChargedAccount        = account,
                Amount                = 20,
                AmountWithoutExchange = 20
            };

            repository.Save(transaction);
            Assert.AreSame(transaction, _recurringTransactionDataAccessMock.RecurringTransactionTestList[0]);

            repository.Delete(transaction);

            Assert.IsFalse(_recurringTransactionDataAccessMock.RecurringTransactionTestList.Any());
            Assert.IsFalse(repository.Data.Any());
        }
        public void RecurringTransactionRepository_Save()
        {
            var recurringTransactionDataAccessMock = new RecurringTransactionDataAccessMock();
            var repository = new RecurringTransactionRepository(recurringTransactionDataAccessMock);

            var account = new Account
            {
                Name = "TestAccount"
            };

            var transaction = new RecurringTransaction
            {
                ChargedAccount = account,
                Amount = 20,
                AmountWithoutExchange = 20
            };

            repository.Save(transaction);

            Assert.IsTrue(transaction == recurringTransactionDataAccessMock.RecurringTransactionTestList[0]);
            Assert.IsTrue(account == recurringTransactionDataAccessMock.RecurringTransactionTestList[0].ChargedAccount);
        }
        public void TransactionRepository_SaveWithouthAccount()
        {
            try
            {
                var recurringTransactionDataAccessMock = new RecurringTransactionDataAccessMock();
                var repository = new RecurringTransactionRepository(recurringTransactionDataAccessMock);

                var transaction = new RecurringTransaction
                {
                    Amount = 20,
                    AmountWithoutExchange = 20
                };

                repository.Save(transaction);
            }
            catch (InvalidDataException)
            {
                return;
            }
            catch (Exception)
            {
                Assert.Fail("wrong exception.");
            }
            Assert.Fail("No excpetion thrown");
        }