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 SetRelatedTransactions(Account account)
 {
     RelatedTransactions = transactionRepository
         .GetRelatedTransactions(account)
         .OrderByDescending(x => x.Date)
         .ToList();
 }
        public void Save_DifferentTransactionTypes_CorrectlySaved(TransactionType type)
        {
            var transactionDataAccessMock = new TransactionDataAccessMock();
            var repository = new TransactionRepository(transactionDataAccessMock,
                new RecurringTransactionDataAccessMock());

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

            var transaction = new FinancialTransaction
            {
                ChargedAccount = account,
                TargetAccount = null,
                Amount = 20,
                Type = (int) type
            };

            repository.Save(transaction);

            transactionDataAccessMock.FinancialTransactionTestList[0].ShouldBeSameAs(transaction);
            transactionDataAccessMock.FinancialTransactionTestList[0].ChargedAccount.ShouldBeSameAs(account);
            transactionDataAccessMock.FinancialTransactionTestList[0].TargetAccount.ShouldBeNull();
            transactionDataAccessMock.FinancialTransactionTestList[0].Type.ShouldBe((int) type);
        }
        public void Delete_None_AccountDeleted()
        {
            var testList = new List<Account>();

            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.SaveItem(It.IsAny<Account>()))
                .Callback((Account acc) => testList.Add(acc));

            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalance = 6034
            };

            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>
            {
                account
            });

            var repository = new AccountRepository(accountDataAccessSetup.Object);

            repository.Delete(account);

            Assert.IsFalse(testList.Any());
            Assert.IsFalse(repository.Data.Any());
        }
        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 void Save_InputName_CorrectNameAssigned(string nameInput, string nameExpected, string culture)
        {
            var testList = new List<Account>();

            // Set test culture
            CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
            Strings.Culture = new CultureInfo(culture);

            var accountDataAccessSetup = new Mock<IDataAccess<Account>>();
            accountDataAccessSetup.Setup(x => x.SaveItem(It.IsAny<Account>()))
                .Callback((Account acc) => testList.Add(acc));

            accountDataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>());

            var accountRepository = new AccountRepository(accountDataAccessSetup.Object);

            var account = new Account
            {
                Name = nameInput,
                CurrentBalance = 6034
            };

            accountRepository.Save(account);

            testList[0].ShouldBeSameAs(account);
            testList[0].Name.ShouldBe(nameExpected);

            // Reset Culture
            CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
            Strings.Culture = CultureInfo.CurrentCulture;
        }
 /// <summary>
 ///     Initializes the ViewModel
 /// </summary>
 /// <param name="isEdit">Indicates if the view is in edit or create mode.</param>
 /// <param name="selectedAccountId">if in edit mode, this is the selected account.</param>
 public void Init(bool isEdit, int selectedAccountId)
 {
     IsEdit = isEdit;
     SelectedAccount = selectedAccountId != 0
         ? accountRepository.Data.First(x => x.Id == selectedAccountId)
         : new Account();
 }
        public void AccountRepository_Update()
        {
            const string newName = "newName";

            var repository =
                new AccountRepository(
                    new AccountDataAccess(new SqliteConnectionCreator(new WindowsSqliteConnectionFactory())));

            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalance = 6034
            };

            repository.Save(account);

            repository.Data[0].ShouldBeSameAs(account);

            account.Name = newName;

            repository.Save(account);

            repository.Data.Count().ShouldBe(1);
            repository.Data[0].Name.ShouldBe(newName);
        }
        public void SaveToDatabase_MultipleAccounts_AllSaved()
        {
            var account1 = new Account
            {
                Name = "Account1",
                CurrentBalance = 1234
            };

            var account2 = new Account
            {
                Name = "Account2",
                CurrentBalance = 999
            };

            var account3 = new Account();
            var account4 = new Account();

            var dataAccess = new AccountDataAccess(connectionCreator);
            dataAccess.SaveItem(account1);
            dataAccess.SaveItem(account2);
            dataAccess.SaveItem(account3);
            dataAccess.SaveItem(account4);

            var resultList = dataAccess.LoadList();

            Assert.AreNotSame(account1, account2);
            Assert.IsTrue(resultList.Any(x => x.Id == account1.Id && x.Name == account1.Name));
            Assert.IsTrue(resultList.Any(x => x.Id == account2.Id && x.Name == account2.Name));
        }
        public void TransactionRepository_Update()
        {
            var dbHelper = new SqliteConnectionCreator(new WindowsSqliteConnectionFactory());

            using (var db = dbHelper.GetConnection())
            {
                db.DeleteAll<FinancialTransaction>();
            }

            var repository = new TransactionRepository(new TransactionDataAccess(dbHelper),
                new RecurringTransactionDataAccess(dbHelper));
            var account = new Account
            {
                Name = "TestAccount"
            };

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

            repository.Save(transaction);
            repository.Data.Count.ShouldBe(1);
            repository.Data[0].ShouldBeSameAs(transaction);

            transaction.Amount = 30;

            repository.Save(transaction);

            repository.Data.Count.ShouldBe(1);
            repository.Data[0].Amount.ShouldBe(30);
        }
        public void Converter_TransferSameAccount_Minus()
        {
            ClearAll();
            Setup();

            var account = new Account
            {
                Id = 4,
                CurrentBalance = 400
            };

            var mock = new Mock<IAccountRepository>();
            mock.Setup(x => x.Load(It.IsAny<Expression<Func<Account, bool>>>()));
            mock.SetupGet(x => x.Selected).Returns(account);

            Mvx.RegisterSingleton(mock.Object);

            new PaymentAmountConverter()
                .Convert(new Payment
                {
                    Amount = 80,
                    Type = (int) PaymentType.Transfer,
                    ChargedAccountId = account.Id,
                    ChargedAccount = account
                }, null, account, null)
                .ShouldBe("- " + 80.ToString("C"));
        }
        public void Save_DifferentPaymentTypes_CorrectlySaved()
        {
            var accountRepositorySetup = new Mock<IAccountRepository>();
            accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>());

            var categoryDataAccessSetup = new Mock<IRepository<Category>>();
            categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>());

            var paymentDataAccessMock = new PaymentDataAccessMock();
            var repository = new PaymentRepository(paymentDataAccessMock,
                new RecurringPaymentDataAccessMock(),
                accountRepositorySetup.Object,
                categoryDataAccessSetup.Object);

            var account = new Account
            {
                Id = 2,
                Name = "TestAccount"
            };

            var payment = new Payment
            {
                ChargedAccount = account,
                TargetAccount = null,
                Amount = 20,
                Type = (int) PaymentType.Income
            };

            repository.Save(payment);

            Assert.AreSame(payment, paymentDataAccessMock.PaymentTestList[0]);
            Assert.AreEqual((int) PaymentType.Income, paymentDataAccessMock.PaymentTestList[0].Type);
        }
        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 Save_TransferTransaction_CorrectlySaved()
        {
            var accountRepoSetup = new Mock<IDataAccess<Account>>();
            accountRepoSetup.Setup(x => x.LoadList(null)).Returns(new List<Account>());

            var transactionDataAccessMock = new TransactionDataAccessMock();
            var repository = new TransactionRepository(transactionDataAccessMock,
                new RecurringTransactionDataAccessMock());

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

            var targetAccount = new Account
            {
                Name = "targetAccount"
            };

            var transaction = new FinancialTransaction
            {
                ChargedAccount = account,
                TargetAccount = targetAccount,
                Amount = 20,
                Type = (int) TransactionType.Transfer
            };

            repository.Save(transaction);

            transactionDataAccessMock.FinancialTransactionTestList[0].ShouldBeSameAs(transaction);
            transactionDataAccessMock.FinancialTransactionTestList[0].ChargedAccount.ShouldBeSameAs(account);
            transactionDataAccessMock.FinancialTransactionTestList[0].TargetAccount.ShouldBeSameAs(targetAccount);
            transactionDataAccessMock.FinancialTransactionTestList[0].Type.ShouldBe((int) TransactionType.Transfer);
        }
Exemplo n.º 15
0
        private void EditAccount(Account account)
        {
            modifyAccountViewModel.IsEdit = true;
            modifyAccountViewModel.SelectedAccount = account;

            ShowViewModel<ModifyAccountViewModel>();
        }
Exemplo n.º 16
0
 private async void Delete(Account item)
 {
     if (await dialogService.ShowConfirmMessage(Strings.DeleteTitle, Strings.DeleteAccountConfirmationMessage))
     {
         accountRepository.Delete(item);
         balanceViewModel.UpdateBalance();
     }
 }
        private void GoToPaymentOverView(Account account)
        {
            if (account == null)
            {
                return;
            }

            accountRepository.Selected = account;
            ShowViewModel<PaymentListViewModel>();
        }
Exemplo n.º 18
0
        private void GoToTransactionOverView(Account account)
        {
            if (account == null)
            {
                return;
            }

            accountRepository.Selected = account;
            ShowViewModel<TransactionListViewModel>();
        }
 /// <summary>
 ///     returns a list with transaction who is related to this account
 /// </summary>
 /// <param name="account">account to search the related</param>
 /// <returns>List of transactions</returns>
 public IEnumerable<FinancialTransaction> GetRelatedTransactions(Account account)
 {
     return Data
         .Where(x => x.ChargedAccount != null)
         .Where(
             x =>
                 x.ChargedAccount.Id == account.Id ||
                 (x.TargetAccount != null && x.TargetAccount.Id == account.Id))
         .OrderByDescending(x => x.Date)
         .ToList();
 }
Exemplo n.º 20
0
        private void GoToTransactionOverView(Account account)
        {
            if (account == null)
            {
                return;
            }

            accountRepository.Selected = account;
            transactionListViewModel.LoadedCommand.Execute();

            ShowViewModel<TransactionListViewModel>();
        }
        private async void Delete(Account item)
        {
            if (item == null)
            {
                return;
            }

            if (await dialogService.ShowConfirmMessage(Strings.DeleteTitle, Strings.DeleteAccountConfirmationMessage))
            {
                accountRepository.Delete(item);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        ///     SaveItem a new item or update an existin one.
        /// </summary>
        /// <param name="item">item to save</param>
        public void Save(Account item)
        {
            if (string.IsNullOrWhiteSpace(item.Name))
            {
                item.Name = Strings.NoNamePlaceholderLabel;
            }

            if (item.Id == 0)
            {
                data.Add(item);
            }
            dataAccess.SaveItem(item);
        }
Exemplo n.º 23
0
        /// <summary>
        ///     Save a new account or update an existing one.
        /// </summary>
        /// <param name="account">accountToDelete to save</param>
        public void Save(Account account)
        {
            if (string.IsNullOrWhiteSpace(account.Name))
            {
                account.Name = Strings.NoNamePlaceholderLabel;
            }

            if (account.Id == 0)
            {
                data.Add(account);
            }
            dataAccess.SaveItem(account);
        }
Exemplo n.º 24
0
        public void DeleteAssociatedPaymentsFromDatabase(Account account)
        {
            if (paymentRepository.Data == null)
            {
                return;
            }

            var paymentToDelete = paymentRepository.GetRelatedPayments(account);

            foreach (var payment in paymentToDelete)
            {
                paymentRepository.Delete(payment);
            }
        }
Exemplo n.º 25
0
        public void DeleteAssociatedTransactionsFromDatabase(Account account)
        {
            if (transactionRepository.Data == null)
            {
                return;
            }

            var transactionsToDelete = transactionRepository.GetRelatedTransactions(account);

            foreach (var transaction in transactionsToDelete)
            {
                transactionRepository.Delete(transaction);
            }
        }
        public void AccountRepository_Save()
        {
            var accountDataAccessMock = new AccountDataAccessMock();
            var account = new Account
            {
                Name = "Sparkonto",
                CurrentBalanceWithoutExchange = 6034,
                CurrentBalance = 6034,
                Currency = "CHF"
            };

             accountDataAccessMock.Save(account);

            Assert.IsTrue(account == accountDataAccessMock.AccountTestList[0]);
        }
        public void Converter_TransferSameAccount_Minus()
        {
            var account = new Account
            {
                Id = 4,
                CurrentBalance = 400
            };

            new TransactionAmountConverter()
                .Convert(new FinancialTransaction
                {
                    Amount = 80,
                    Type = (int) TransactionType.Transfer,
                    ChargedAccount = account
                }, null, account, null)
                .ShouldBe("- " + 80.ToString("C"));
        }
        public void AccountRepository_SaveWithoutName()
        {
            var accountDataAccessMock = new AccountDataAccessMock();
            var repository = new AccountRepository(accountDataAccessMock);

            var account = new Account
            {
                CurrentBalanceWithoutExchange = 6034,
                CurrentBalance = 6034,
                Currency = "CHF"
            };

            repository.Save(account);

            Assert.AreSame(account, accountDataAccessMock.AccountTestList[0]);
            Assert.IsTrue(accountDataAccessMock.AccountTestList[0].Name == Strings.NoNamePlaceholderLabel);
        }
        public void SaveToDatabase_NewAccount_CorrectId()
        {
            var name = "Sparkonto";
            var balance = 456468;

            var account = new Account
            {
                Name = name,
                CurrentBalance = balance
            };

            new AccountDataAccess(connectionCreator).SaveItem(account);

            Assert.IsTrue(account.Id >= 1);
            Assert.AreEqual(name, account.Name);
            Assert.AreEqual(balance, account.CurrentBalance);
        }
        public void DeleteAssociatedTransactionsFromDatabase_Account_DeleteRightTransactions()
        {
            var resultList = new List<int>();

            var account1 = new Account
            {
                Id = 3,
                Name = "just an account",
                CurrentBalance = 500
            };
            var account2 = new Account
            {
                Id = 4,
                Name = "just an account",
                CurrentBalance = 900
            };

            var trans1 = new FinancialTransaction
            {
                Id = 1,
                ChargedAccount = account1,
                ChargedAccountId = account1.Id
            };

            var transRepoSetup = new Mock<ITransactionRepository>();
            transRepoSetup.SetupAllProperties();
            transRepoSetup.Setup(x => x.Delete(It.IsAny<FinancialTransaction>()))
                .Callback((FinancialTransaction trans) => resultList.Add(trans.Id));
            transRepoSetup.Setup(x => x.GetRelatedTransactions(It.IsAny<Account>()))
                .Returns(new List<FinancialTransaction>
                {
                    trans1
                });

            var repo = transRepoSetup.Object;
            repo.Data = new ObservableCollection<FinancialTransaction>();

            new TransactionManager(repo, new Mock<IAccountRepository>().Object, new Mock<IDialogService>().Object)
                .DeleteAssociatedTransactionsFromDatabase(account1);

            resultList.Count.ShouldBe(1);
            resultList.First().ShouldBe(trans1.Id);
        }