Beispiel #1
0
        public void CheckIfRepeatable_Biweekly_ValidatedRecurrence()
        {
            var account = new Account {
                Id = 2
            };

            var recurringPayment = new RecurringPayment {
                Id               = 4,
                Recurrence       = (int)PaymentRecurrence.Biweekly,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                                                     new Payment {
                Date = DateTime.Today.AddDays(-15), IsCleared = true
            })
            .ShouldBeTrue();
        }
        /// <summary>
        ///     Checks if one of the recurring payment has to be repeated
        /// </summary>
        public void CheckRecurringPayments()
        {
            var paymentList = paymentManager.LoadRecurringPaymentList();

            foreach (var payment in paymentList.Where(x => x.ChargedAccount != null))
            {
                var relatedPayment = GetLastOccurence(payment);

                if (RecurringPaymentHelper.CheckIfRepeatable(payment.RecurringPayment, relatedPayment))
                {
                    var newPayment = RecurringPaymentHelper.GetPaymentFromRecurring(payment.RecurringPayment);

                    var paymentSucceded = paymentRepository.Save(newPayment);
                    var accountSucceded = paymentManager.AddPaymentAmount(newPayment);
                    if (paymentSucceded && accountSucceded)
                    {
                        SettingsHelper.LastDatabaseUpdate = DateTime.Now;
                    }
                }
            }
        }
Beispiel #3
0
        public void CheckIfRepeatable_UnclearedPayment_ReturnFalse()
        {
            var account = new Account {
                Id = 2
            };

            var recurringPayment = new RecurringPayment
            {
                Id               = 4,
                Recurrence       = (int)PaymentRecurrence.Weekly,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                                                     new Payment {
                Date = DateTime.Today.AddDays(11)
            }).ShouldBeFalse();
        }
Beispiel #4
0
        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 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
                }
            };

            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.ShouldBe(enddate);
            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);
        }
Beispiel #5
0
        public void CheckIfRepeatable_ValidatedRecurrence(PaymentRecurrence recurrence, int amountOfDaysPassed)
        {
            var account = new AccountViewModel {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id               = 4,
                Recurrence       = recurrence,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                                                     new PaymentViewModel {
                Date = DateTime.Today.AddDays(-amountOfDaysPassed), IsCleared = true
            })
            .ShouldBeTrue();
        }
Beispiel #6
0
        public void CheckIfRepeatable_ValidatedRecurrenceMonthly_False()
        {
            var account = new AccountViewModel {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id               = 4,
                Recurrence       = PaymentRecurrence.Monthly,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                                                     new PaymentViewModel {
                Date = DateTime.Today.GetFirstDayOfMonth(), IsCleared = true
            })
            .ShouldBeFalse();
        }
Beispiel #7
0
        public void GetPaymentFromRecurring_CorrectMappedPayment(PaymentRecurrence recurrence)
        {
            var account = new AccountViewModel {
                Id = 2
            };

            var recurringPayment = new RecurringPaymentViewModel
            {
                Id               = 4,
                Recurrence       = recurrence,
                StartDate        = new DateTime(2015, 08, DateTime.Today.Day),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.ChargedAccount.ShouldBe(account);
            result.ChargedAccountId.ShouldBe(account.Id);
            result.Amount.ShouldBe(105);
            result.Date.ShouldBe(DateTime.Today);
        }
Beispiel #8
0
        public void GetPaymentFromRecurring_MonthlyPayment_CorrectMappedFinancialTrans()
        {
            var account = new Account {
                Id = 2
            };
            var dayOfMonth = 26;

            var recurringPayment = new RecurringPayment {
                Id               = 4,
                Recurrence       = (int)PaymentRecurrence.Monthly,
                StartDate        = new DateTime(2015, 08, dayOfMonth),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.ChargedAccount.ShouldBe(account);
            result.ChargedAccountId.ShouldBe(account.Id);
            result.Amount.ShouldBe(105);
            result.Date.ShouldBe(new DateTime(DateTime.Today.Year, DateTime.Today.Month, dayOfMonth));
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
            public async Task <Unit> Handle(CreateRecurringPaymentsCommand request, CancellationToken cancellationToken)
            {
                List <RecurringPayment> recurringPayments = await contextAdapter.Context
                                                            .RecurringPayments
                                                            .Include(x => x.ChargedAccount)
                                                            .Include(x => x.TargetAccount)
                                                            .Include(x => x.Category)
                                                            .Include(x => x.RelatedPayments)
                                                            .AsQueryable()
                                                            .IsNotExpired()
                                                            .ToListAsync();

                var recPaymentsToCreate = recurringPayments
                                          .Where(x => x.RelatedPayments.Any())
                                          .Where(x => RecurringPaymentHelper.CheckIfRepeatable(x.RelatedPayments
                                                                                               .OrderByDescending(d => d.Date)
                                                                                               .First()))
                                          .Select(x => new Payment(RecurringPaymentHelper.GetPaymentDateFromRecurring(x),
                                                                   x.Amount,
                                                                   x.Type,
                                                                   x.ChargedAccount,
                                                                   x.TargetAccount,
                                                                   x.Category,
                                                                   x.Note ?? "",
                                                                   x))
                                          .ToList();

                recPaymentsToCreate.ForEach(x => x.RecurringPayment?.SetLastRecurrenceCreatedDate());

                logger.Info($"Create {recPaymentsToCreate.Count} recurring payments.");

                contextAdapter.Context.Payments.AddRange(recPaymentsToCreate);
                await contextAdapter.Context.SaveChangesAsync();

                return(Unit.Value);
            }
Beispiel #12
0
        public void GetPaymentFromRecurring_RecurringPayment_CorrectMappedFinancialTrans(
            PaymentRecurrence recurrence)
        {
            var account = new Account {
                Id = 2
            };

            var recurringPayment = new RecurringPayment
            {
                Id               = 4,
                Recurrence       = (int)recurrence,
                StartDate        = new DateTime(2015, 08, 25),
                ChargedAccountId = 2,
                ChargedAccount   = account,
                Amount           = 105
            };

            var result = RecurringPaymentHelper.GetPaymentFromRecurring(recurringPayment);

            result.ChargedAccount.ShouldBe(account);
            result.ChargedAccountId.ShouldBe(account.Id);
            result.Amount.ShouldBe(105);
            result.Date.ShouldBe(DateTime.Today);
        }