public void GetRecurringFromPayment_IsNotEndless_EnddateSet() { // Arrange var payment = new Payment { Data = new PaymentEntity { Amount = 12, Category = new CategoryEntity { Name = "category" }, ChargedAccount = new AccountEntity { Name = "account" }, Date = DateTime.Now, IsCleared = false, Note = "note" } }; var enddate = DateTime.Now.AddMonths(2); // Act var recurringPayment = RecurringPaymentHelper.GetRecurringFromPayment(payment, false, PaymentRecurrence.Daily, enddate); // Assert Assert.NotNull(recurringPayment.Data.EndDate); Assert.Equal(enddate, recurringPayment.Data.EndDate.Value); }
public void GetRecurringFromPayment_IsEndless_EnddateNull() { // Arrange var payment = new Payment { Data = new PaymentEntity { Amount = 12, Category = new CategoryEntity { Name = "category" }, ChargedAccount = new AccountEntity { Name = "account" }, Date = DateTime.Now, IsCleared = false, Note = "note" } }; // Act var recurringPayment = RecurringPaymentHelper.GetRecurringFromPayment(payment, true, PaymentRecurrence.Daily); // Assert Assert.Null(recurringPayment.Data.EndDate); }
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); }
private async Task PrepareRecurringPayment() { if ((IsEdit && await paymentManager.CheckForRecurringPayment(SelectedPayment)) || SelectedPayment.IsRecurring) { SelectedPayment.RecurringPayment = RecurringPaymentHelper. GetRecurringFromPayment(SelectedPayment, IsEndless, Recurrence, EndDate); } }
private async Task PrepareRecurringPayment() { if (IsEdit && selectedPayment.IsRecurring && await dialogService.ShowConfirmMessage(Strings.ChangeSubsequentPaymentTitle, Strings.ChangeSubsequentPaymentMessage, Strings.UpdateAllLabel, Strings.JustThisLabel) || !IsEdit && SelectedPayment.IsRecurring) { SelectedPayment.RecurringPayment = new RecurringPaymentViewModel( RecurringPaymentHelper.GetRecurringFromPayment(SelectedPayment.Payment, IsEndless, Recurrence, EndDate)); } }
public async void Save_WithRecurringPayment_GetRecurringPaymentFromHelper() { // Arrange var paymentRepository = new PaymentRepository(ambientDbContextLocator); var recurringPaymentRepository = new RecurringPaymentRepository(ambientDbContextLocator); var accountRepository = new AccountRepository(ambientDbContextLocator); AccountEntity testAccount; using (var dbContextScope = dbContextScopeFactory.Create()) { testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await dbContextScope.SaveChangesAsync(); } var testEntry = new PaymentViewModel(new Payment { Data = { ChargedAccount = testAccount, Date = DateTime.Now, IsRecurring = true, Note = "Testtext" } }); testEntry.RecurringPayment = new RecurringPaymentViewModel( RecurringPaymentHelper.GetRecurringFromPayment(testEntry.Payment, true, PaymentRecurrence.Bimonthly, DateTime.Now)); var paymentService = new PaymentService(dbContextScopeFactory, paymentRepository, recurringPaymentRepository, accountRepository); // Act await paymentService.SavePayment(testEntry.Payment); var payment = await paymentService.GetById(testEntry.Payment.Data.Id); // Assert Assert.NotNull(payment); }
public async void Save_WithRecurringPayment_GetRecurringPaymentFromHelper() { // Arrange var factory = new DbFactory(); var unitOfWork = new UnitOfWork(factory); var repository = new PaymentRepository(factory); var accountRepository = new AccountRepository(factory); var testAccount = new AccountEntity { Name = "testAccount" }; accountRepository.Add(testAccount); await unitOfWork.Commit(); var testEntry = new PaymentViewModel(new Payment { Data = { ChargedAccount = testAccount, Date = DateTime.Now, IsRecurring = true, Note = "Testtext" } }); testEntry.RecurringPayment = new RecurringPaymentViewModel( RecurringPaymentHelper.GetRecurringFromPayment(testEntry.Payment, true, PaymentRecurrence.Bimonthly, DateTime.Now)); var paymentService = new PaymentService(repository, unitOfWork); // Act await paymentService.SavePayment(testEntry.Payment); await unitOfWork.Commit(); var payment = await paymentService.GetById(testEntry.Payment.Data.Id); // Assert Assert.NotNull(payment); }
public void GetRecurringFromPayment_Endless(PaymentRecurrence recurrence, PaymentType type) { // Arrange var startDate = new DateTime(2015, 03, 12); var enddate = Convert.ToDateTime("7.8.2016"); var payment = new Payment { Data = { ChargedAccount = new AccountEntity { Id = 3 }, TargetAccount = new AccountEntity { Id = 8 }, Category = new CategoryEntity { Id = 16 }, Date = startDate, Amount = 2135, IsCleared = false, Type = type, IsRecurring = true } }; // Act var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, true, recurrence, enddate); recurring.Data.ChargedAccount.Id.ShouldBe(3); recurring.Data.TargetAccount.Id.ShouldBe(8); recurring.Data.StartDate.ShouldBe(startDate); recurring.Data.EndDate.ShouldBeNull(); recurring.Data.IsEndless.ShouldBe(true); recurring.Data.Amount.ShouldBe(payment.Data.Amount); recurring.Data.Category.Id.ShouldBe(payment.Data.Category.Id); recurring.Data.Type.ShouldBe(type); recurring.Data.Recurrence.ShouldBe(recurrence); recurring.Data.Note.ShouldBe(payment.Data.Note); }
public void GetRecurringFromPayment_Endless(PaymentRecurrence recurrence, PaymentType type) { var startDate = new DateTime(2015, 03, 12); var enddate = Convert.ToDateTime("7.8.2016"); var payment = new PaymentViewModel { ChargedAccount = new AccountViewModel { Id = 3 }, TargetAccount = new AccountViewModel { Id = 8 }, Category = new CategoryViewModel { Id = 16 }, Date = startDate, Amount = 2135, IsCleared = false, Type = type, IsRecurring = true }; var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, true, recurrence, enddate); recurring.ChargedAccount.Id.ShouldBe(3); recurring.TargetAccount.Id.ShouldBe(8); recurring.StartDate.ShouldBe(startDate); recurring.EndDate.ShouldBe(enddate); recurring.IsEndless.ShouldBe(true); recurring.Amount.ShouldBe(payment.Amount); recurring.Category.Id.ShouldBe(payment.Category.Id); recurring.Type.ShouldBe(type); recurring.Recurrence.ShouldBe(recurrence); recurring.Note.ShouldBe(payment.Note); }
public void GetRecurringFromPayment_MonthlyEndlessTransfer() { var startDate = new DateTime(2015, 03, 12); var enddate = Convert.ToDateTime("7.8.2016"); var payment = new Payment { ChargedAccount = new Account { Id = 3 }, TargetAccount = new Account { Id = 8 }, Category = new Category { Id = 16 }, Date = startDate, Amount = 2135, IsCleared = false, Type = (int)PaymentType.Transfer, IsRecurring = true }; var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, true, (int)PaymentRecurrence.Monthly, enddate); recurring.ChargedAccount.Id.ShouldBe(3); recurring.TargetAccount.Id.ShouldBe(8); recurring.StartDate.ShouldBe(startDate); recurring.EndDate.ShouldBe(enddate); recurring.IsEndless.ShouldBe(true); recurring.Amount.ShouldBe(payment.Amount); recurring.Category.Id.ShouldBe(payment.Category.Id); recurring.Type.ShouldBe((int)PaymentType.Transfer); recurring.Recurrence.ShouldBe((int)PaymentRecurrence.Monthly); recurring.Note.ShouldBe(payment.Note); }
public void GetRecurringFromPayment(int recurrence, string date, bool isEndless, int type) { var startDate = new DateTime(2015, 03, 12); var enddate = Convert.ToDateTime(date); var payment = new Payment { ChargedAccount = new Account { Id = 3 }, TargetAccount = new Account { Id = 8 }, Category = new Category { Id = 16 }, Date = startDate, Amount = 2135, IsCleared = false, Type = type, IsRecurring = true }; var recurring = RecurringPaymentHelper.GetRecurringFromPayment(payment, isEndless, recurrence, enddate); recurring.ChargedAccount.Id.ShouldBe(3); recurring.TargetAccount.Id.ShouldBe(8); recurring.StartDate.ShouldBe(startDate); recurring.EndDate.ShouldBe(enddate); recurring.IsEndless.ShouldBe(isEndless); recurring.Amount.ShouldBe(payment.Amount); recurring.Category.Id.ShouldBe(payment.Category.Id); recurring.Type.ShouldBe(type); recurring.Recurrence.ShouldBe(recurrence); recurring.Note.ShouldBe(payment.Note); }