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 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 SaveWithouthAccount_NoAccount_InvalidDataException() { 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 payment = new Payment { Amount = 20 }; repository.Save(payment); }
public void GoToAddPayment_Expense_CorrectPreparation() { Setup(); // for navigation parsing Ioc.RegisterSingleton<IMvxStringToTypeParser>(new MvxStringToTypeParser()); var dbHelper = new Mock<IDatabaseManager>().Object; var accountRepository = new AccountRepository(new AccountDataAccess(dbHelper), new Mock<INotificationService>().Object); var paymentRepository = new PaymentRepository(new PaymentDataAccess(dbHelper), new RecurringPaymentDataAccess(dbHelper), accountRepository, new CategoryRepository(new CategoryDataAccess(dbHelper), new Mock<INotificationService>().Object), new Mock<INotificationService>().Object); var paymentManager = new PaymentManager(paymentRepository, accountRepository, new Mock<IDialogService>().Object); var defaultManager = new DefaultManager(accountRepository); var modifyPaymentViewModel = new ModifyPaymentViewModel(paymentRepository, accountRepository, new Mock<IDialogService>().Object, paymentManager, defaultManager); var mainViewModel = new MainViewModel(); mainViewModel.GoToAddPaymentCommand.Execute(PaymentType.Expense.ToString()); modifyPaymentViewModel.IsEdit.ShouldBeFalse(); modifyPaymentViewModel.IsEndless.ShouldBeTrue(); modifyPaymentViewModel.IsTransfer.ShouldBeFalse(); modifyPaymentViewModel.SelectedPayment.Type.ShouldBe((int) PaymentType.Expense); }
public void LoadRecurringList_NoParameters_ListWithRecurringTrans() { 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) { Data = new ObservableCollection<Payment>(new List<Payment> { new Payment { Id = 1, IsRecurring = true, RecurringPayment = new RecurringPayment {Id = 1, IsEndless = true}, RecurringPaymentId = 1 }, new Payment {Id = 2, IsRecurring = false}, new Payment { Id = 3, IsRecurring = true, RecurringPayment = new RecurringPayment {Id = 2, IsEndless = false, EndDate = DateTime.Today.AddDays(10)}, RecurringPaymentId = 2 }, new Payment { Id = 4, IsRecurring = true, RecurringPayment = new RecurringPayment {Id = 3, IsEndless = false, EndDate = DateTime.Today.AddDays(-10)}, RecurringPaymentId = 3 } }) }; var result = repo.LoadRecurringList().ToList(); Assert.AreEqual(2, result.Count); Assert.AreEqual(1, result[0].Id); Assert.AreEqual(3, result[1].Id); }
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); }
public void Load_Payment_DataInitialized() { 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> { new Payment {Id = 10}, new Payment {Id = 15} }); var categoryDataAccessSetup = new Mock<IRepository<Category>>(); categoryDataAccessSetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>()); var paymentRepository = new PaymentRepository(dataAccessSetup.Object, new Mock<IDataAccess<RecurringPayment>>().Object, accountRepositorySetup.Object, categoryDataAccessSetup.Object, new Mock<INotificationService>().Object); paymentRepository.Load(); Assert.IsTrue(paymentRepository.Data.Any(x => x.Id == 10)); Assert.IsTrue(paymentRepository.Data.Any(x => x.Id == 15)); }
public void GetUnclearedPayments_AccountNull() { 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); repository.Data.Add(new Payment { Amount = 55, Date = DateTime.Today.AddDays(-1), Note = "this is a note!!!", IsCleared = false } ); var payments = repository.GetUnclearedPayments(); Assert.AreEqual(1, payments.Count()); }
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()); }
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_AccessCache() { var accountRepositorySetup = new Mock<IAccountRepository>(); accountRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Account>()); var categoryRepositorySetup = new Mock<IRepository<Category>>(); categoryRepositorySetup.SetupGet(x => x.Data).Returns(new ObservableCollection<Category>()); var paymentRepo = new PaymentRepository(new PaymentDataAccessMock(), new RecurringPaymentDataAccessMock(), accountRepositorySetup.Object, categoryRepositorySetup.Object, new Mock<INotificationService>().Object); Assert.IsFalse(paymentRepo.Data.Any()); }
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 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); }