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 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, new Mock<INotificationService>().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 Save_EmptyName_CorrectDefault() { var testList = new List<Account>(); const string nameInput = ""; 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, new Mock<INotificationService>().Object); var account = new Account { Name = nameInput, CurrentBalance = 6034 }; accountRepository.Save(account); Assert.AreSame(testList[0], account); Assert.AreSame(testList[0].Name, account.Name); }
public void CheckRecurringPayments_Daily_CorrectPaymentsCreated() { //Setup var sqliteConnector = new SqliteConnectionCreator(new WindowsSqliteConnectionFactory(), new MvxWindowsCommonFileStore()); var accountRepo = new AccountRepository(new AccountDataAccess(sqliteConnector)); var paymentRepo = new PaymentRepository(new PaymentDataAccess(sqliteConnector), new RecurringPaymentDataAccess(sqliteConnector), accountRepo, new CategoryRepository(new CategoryDataAccess(sqliteConnector))); var account = new Account { Name = "test1", CurrentBalance = 100 }; accountRepo.Save(account); var payment = new Payment { ChargedAccount = account, Amount = 10, Date = DateTime.Today.AddDays(-1), IsRecurring = true }; payment.RecurringPayment = RecurringPaymentHelper. GetRecurringFromPayment(payment, true, (int) PaymentRecurrence.Daily, DateTime.Now.AddYears(1)); paymentRepo.Save(payment); //Execution new RecurringPaymentManager(paymentRepo, accountRepo).CheckRecurringPayments(); //Assert Assert.AreEqual(90, account.CurrentBalance); Assert.AreEqual(90, accountRepo.Data[0].CurrentBalance); Assert.AreEqual(2, paymentRepo.Data.Count); Assert.IsTrue(paymentRepo.Data[0].IsCleared); Assert.IsTrue(paymentRepo.Data[1].IsCleared); Assert.IsTrue(paymentRepo.Data[0].IsRecurring); Assert.IsTrue(paymentRepo.Data[1].IsRecurring); Assert.AreNotEqual(0, paymentRepo.Data[0].RecurringPaymentId); Assert.AreNotEqual(0, paymentRepo.Data[1].RecurringPaymentId); Assert.IsNotNull(paymentRepo.Data[0].RecurringPayment); Assert.IsNotNull(paymentRepo.Data[1].RecurringPayment); }
public void Init(bool isEdit) { IsEdit = isEdit; if (!IsEdit) { SelectedAccount = new Account(); } }
private void GoToPaymentOverView(Account account) { if (account == null) { return; } accountRepository.Selected = account; ShowViewModel<PaymentListViewModel>(); }
/// <summary> /// Deletes the passed account and removes it from cache /// </summary> /// <param name="accountToDelete">accountToDelete to delete</param> public void Delete(Account accountToDelete) { data.Remove(accountToDelete); if (dataAccess.DeleteItem(accountToDelete)) { SettingsHelper.LastDatabaseUpdate = DateTime.Now; } else { notificationService.SendBasicNotification(Strings.ErrorTitleDelete, Strings.ErrorMessageDelete); } }
public void DeleteAssociatedPaymentsFromDatabase(Account account) { if (paymentRepository.Data == null) { return; } var paymentToDelete = paymentRepository.GetRelatedPayments(account); foreach (var payment in paymentToDelete) { paymentRepository.Delete(payment); } }
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 DeleteAssociatedPaymentsFromDatabase_Account_DeleteRightPayments() { 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 payment = new Payment { Id = 1, ChargedAccount = account1, ChargedAccountId = account1.Id }; var paymentRepositorySetup = new Mock<IPaymentRepository>(); paymentRepositorySetup.SetupAllProperties(); paymentRepositorySetup.Setup(x => x.Delete(It.IsAny<Payment>())) .Callback((Payment trans) => resultList.Add(trans.Id)); paymentRepositorySetup.Setup(x => x.GetRelatedPayments(It.IsAny<Account>())) .Returns(new List<Payment> { payment }); var repo = paymentRepositorySetup.Object; repo.Data = new ObservableCollection<Payment>(); new PaymentManager(repo, new Mock<IAccountRepository>().Object, new Mock<IDialogService>().Object) .DeleteAssociatedPaymentsFromDatabase(account1); Assert.AreEqual(1, resultList.Count); Assert.AreEqual(payment.Id, resultList.First()); }
/// <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); } if (dataAccess.SaveItem(account)) { SettingsHelper.LastDatabaseUpdate = DateTime.Now; } else { notificationService.SendBasicNotification(Strings.ErrorTitleSave, Strings.ErrorMessageSave); } }
public void SaveToDatabase_ExistingAccount_CorrectId() { var balance = 456468; var account = new Account { CurrentBalance = balance }; var dataAccess = new AccountDataAccess(connectionCreator); dataAccess.SaveItem(account); Assert.IsNull(account.Name); var id = account.Id; var name = "Sparkonto"; account.Name = name; Assert.AreEqual(id, account.Id); Assert.AreEqual(name, account.Name); Assert.AreEqual(balance, account.CurrentBalance); }
public void Converter_TransferSameAccount_Plus() { ClearAll(); Setup(); var account = new Account { Id = 4, CurrentBalance = 400 }; var mock = new Mock<IAccountRepository>(); mock.SetupGet(x => x.Selected).Returns(account); Mvx.RegisterSingleton(mock.Object); new PaymentAmountConverter() .Convert(new Payment { Amount = 80, Type = (int) PaymentType.Transfer, ChargedAccount = new Account() }, null, new Account(), null) .ShouldBe("+ " + 80.ToString("C")); }
private Func<Payment, Account> GetChargedAccountFunc(Account account) { Func<Payment, Account> accountFunc = trans => Data.FirstOrDefault(x => x.Id == account.Id); return accountFunc; }
/// <summary> /// Removes the payment Amount from the selected account /// </summary> /// <param name="payment">Payment to remove.</param> /// <param name="account">Account to remove the amount from.</param> public void RemovePaymentAmount(Payment payment, Account account) { if (!payment.IsCleared) { return; } PrehandleRemoveIfTransfer(payment); Func<double, double> amountFunc = x => payment.Type == (int) PaymentType.Income ? -x : x; HandlePaymentAmount(payment, amountFunc, GetChargedAccountFunc(account)); }
private async void Delete(Account item) { if (item == null) { return; } if (await dialogService.ShowConfirmMessage(Strings.DeleteTitle, Strings.DeleteAccountConfirmationMessage)) { accountRepository.Delete(item); } BalanceViewModel.UpdateBalanceCommand.Execute(); }
/// <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(); }
private void EditAccount(Account account) { ShowViewModel<ModifyAccountViewModel>(new {isEdit = true, selectedAccountId = account.Id}); }
public void SaveToDatabase_CreateAndUpdateAccount_CorrectlyUpdated() { var firstName = "old name"; var secondName = "new name"; var account = new Account { Name = firstName, CurrentBalance = 1234 }; var dataAccess = new AccountDataAccess(connectionCreator); dataAccess.SaveItem(account); Assert.AreEqual(firstName, dataAccess.LoadList().FirstOrDefault(x => x.Id == account.Id).Name); account.Name = secondName; dataAccess.SaveItem(account); var accounts = dataAccess.LoadList(); Assert.IsFalse(accounts.Any(x => x.Name == firstName)); Assert.AreEqual(secondName, accounts.First(x => x.Id == account.Id).Name); }
public void Save_TransferPayment_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(new PaymentDataAccessMock(), new RecurringPaymentDataAccessMock(), accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object); var account = new Account { Id = 2, Name = "TestAccount" }; var targetAccount = new Account { Id = 3, Name = "targetAccount" }; var payment = new Payment { ChargedAccount = account, ChargedAccountId = 2, TargetAccount = targetAccount, TargetAccountId = 3, Amount = 20, Type = (int) PaymentType.Transfer }; repository.Save(payment); Assert.AreSame(payment, repository.Data[0]); Assert.AreEqual((int) PaymentType.Transfer, repository.Data[0].Type); }
public void DeletePayment_TransferClearedIsFalse_Deleted() { var deletedId = 0; 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 payment = new Payment { Id = 10, ChargedAccountId = account1.Id, ChargedAccount = account1, TargetAccountId = account2.Id, TargetAccount = account2, Amount = 50, Type = (int) PaymentType.Transfer, IsCleared = false }; var paymentDataAccessMockSetup = new Mock<IDataAccess<Payment>>(); paymentDataAccessMockSetup.Setup(x => x.DeleteItem(It.IsAny<Payment>())) .Callback((Payment trans) => deletedId = trans.Id); paymentDataAccessMockSetup.Setup(x => x.SaveItem(It.IsAny<Payment>())); paymentDataAccessMockSetup.Setup(x => x.LoadList(null)).Returns(new List<Payment> {payment}); var recPaymentDataAccessMockSetup = new Mock<IDataAccess<RecurringPayment>>(); recPaymentDataAccessMockSetup.Setup(x => x.DeleteItem(It.IsAny<RecurringPayment>())); recPaymentDataAccessMockSetup.Setup(x => x.LoadList(It.IsAny<Expression<Func<RecurringPayment, bool>>>())) .Returns(new List<RecurringPayment>()); var accountRepositorySetup = new Mock<IAccountRepository>(); accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account> {account1, account2}); var categoryDataAccessSetup = new Mock<IRepository<Category>>(); categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>()); new PaymentRepository(paymentDataAccessMockSetup.Object, recPaymentDataAccessMockSetup.Object, accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object).Delete( payment); Assert.AreEqual(10, deletedId); Assert.AreEqual(500, account1.CurrentBalance); Assert.AreEqual(900, account2.CurrentBalance); }
public void GetUnclearedPayments_FutureDate_PastPayments() { 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 repository = new PaymentRepository(new PaymentDataAccessMock(), new RecurringPaymentDataAccessMock(), accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object); var account = new Account { Id = 2, Name = "TestAccount" }; repository.Save(new Payment { ChargedAccount = account, Amount = 55, Date = Utilities.GetEndOfMonth().AddDays(-1), Note = "this is a note!!!", IsCleared = false } ); var payments = repository.GetUnclearedPayments(); Assert.AreEqual(0, payments.Count()); payments = repository.GetUnclearedPayments(Utilities.GetEndOfMonth()); Assert.AreEqual(1, payments.Count()); }
/// <summary> /// returns a list with payments who are related to this account /// </summary> /// <param name="account">account to search the related</param> /// <returns>List of payments</returns> public IEnumerable<Payment> GetRelatedPayments(Account account) => Data.Where(x => x.ChargedAccountId == account.Id || x.TargetAccountId == account.Id) .OrderByDescending(x => x.Date) .ToList();
public void DeleteFromDatabase_AccountToDelete_CorrectlyDelete() { var account = new Account { Name = "accountToDelete", CurrentBalance = 1234 }; var dataAccess = new AccountDataAccess(connectionCreator); dataAccess.SaveItem(account); Assert.IsTrue(dataAccess.LoadList(x => x.Id == account.Id).Any()); dataAccess.DeleteItem(account); Assert.IsFalse(dataAccess.LoadList(x => x.Id == account.Id).Any()); }
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, new Mock<INotificationService>().Object); repository.Delete(account); Assert.IsFalse(testList.Any()); Assert.IsFalse(repository.Data.Any()); }
public void ReloadData_UnclearedPayment_Clear() { var account = new Account {Id = 1, CurrentBalance = 40}; var payment = new Payment { ChargedAccount = account, ChargedAccountId = 1, IsCleared = false, Date = DateTime.Today.AddDays(-3) }; var accountRepoSetup = new Mock<IAccountRepository>(); accountRepoSetup.SetupAllProperties(); var paymentRepoSetup = new Mock<IPaymentRepository>(); paymentRepoSetup.SetupAllProperties(); paymentRepoSetup.Setup(x => x.GetUnclearedPayments()) .Returns(() => new List<Payment> {payment}); var categoryRepoSetup = new Mock<IRepository<Category>>(); categoryRepoSetup.SetupAllProperties(); var accountRepo = accountRepoSetup.Object; var paymentRepository = paymentRepoSetup.Object; accountRepo.Data = new ObservableCollection<Account>(new List<Account> {account}); new RepositoryManager(accountRepo, paymentRepository, categoryRepoSetup.Object, new PaymentManager(paymentRepository, accountRepo, new Mock<IDialogService>().Object)) .ReloadData(); Assert.IsTrue(payment.IsCleared); }
public void AddItemToDataList_SaveAccount_IsAddedToData() { 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 repository = new PaymentRepository(new PaymentDataAccessMock(), new RecurringPaymentDataAccessMock(), accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object); var account = new Account { Id = 2, Name = "TestAccount" }; var payment = new Payment { ChargedAccount = account, Amount = 20, Type = (int) PaymentType.Transfer }; repository.Save(payment); Assert.IsTrue(repository.Data.Contains(payment)); }
public void PaymentRepository_Delete() { 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(new PaymentDataAccessMock(), new RecurringPaymentDataAccessMock(), accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object); var account = new Account { Id = 2, Name = "TestAccount" }; var payment = new Payment { ChargedAccount = account, ChargedAccountId = 2, Amount = 20 }; repository.Save(payment); Assert.AreSame(payment, repository.Data[0]); repository.Delete(payment); Assert.IsFalse(repository.Data.Any()); }
public void GetRelatedPayments_Account_CorrectAccounts() { var accountRepositorySetup = new Mock<IAccountRepository>(); accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>()); var dataAccessSetup = new Mock<IDataAccess<Payment>>(); dataAccessSetup.Setup(x => x.LoadList(null)).Returns(new List<Payment>()); var categoryDataAccessSetup = new Mock<IRepository<Category>>(); categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>()); var repo = new PaymentRepository(dataAccessSetup.Object, new Mock<IDataAccess<RecurringPayment>>().Object, accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object); var account1 = new Account {Id = 1}; var account3 = new Account {Id = 3}; repo.Data = new ObservableCollection<Payment>(new List<Payment> { new Payment {Id = 2, ChargedAccount = account1, ChargedAccountId = account1.Id}, new Payment {Id = 5, ChargedAccount = account3, ChargedAccountId = account3.Id} }); var result = repo.GetRelatedPayments(account1).ToList(); Assert.AreEqual(1, result.Count); Assert.AreEqual(2, result.First().Id); }