コード例 #1
0
        /// <summary>
        ///     Creates an payment based on the recurring payment.
        /// </summary>
        /// <param name="recurringPayment">The recurring payment the new Payment shall be based on.</param>
        /// <returns>The new created payment</returns>
        public static Payment GetPaymentFromRecurring(RecurringPayment recurringPayment)
        {
            var date = DateTime.Today;

            //If the payment is monthly we want it on the same day of month again.
            if (recurringPayment.Recurrence == (int) PaymentRecurrence.Monthly)
            {
                date = DateTime.Today.AddDays(recurringPayment.StartDate.Day - DateTime.Today.Day);
            }

            return new Payment
            {
                ChargedAccount = recurringPayment.ChargedAccount,
                ChargedAccountId = recurringPayment.ChargedAccountId,
                TargetAccount = recurringPayment.TargetAccount,
                TargetAccountId = recurringPayment.TargetAccountId,
                Date = date,
                IsRecurring = true,
                Amount = recurringPayment.Amount,
                Category = recurringPayment.Category,
                CategoryId = recurringPayment.CategoryId,
                Type = recurringPayment.Type,
                RecurringPaymentId = recurringPayment.Id,
                RecurringPayment = recurringPayment,
                Note = recurringPayment.Note
            };
        }
コード例 #2
0
        public void SaveToDatabase_NewRecurringPayment_CorrectId()
        {
            var amount = 789;

            var payment = new RecurringPayment
            {
                Amount = amount
            };

            new RecurringPaymentDataAccess(connectionCreator).SaveItem(payment);

            Assert.IsTrue(payment.Id >= 1);
            Assert.AreEqual(amount, payment.Amount);
        }
コード例 #3
0
        public void SaveToDatabase_ExistingRecurringPayment_CorrectId()
        {
            var payment = new RecurringPayment();

            var dataAccess = new RecurringPaymentDataAccess(connectionCreator);
            dataAccess.SaveItem(payment);

            Assert.AreEqual(0, payment.Amount);

            var id = payment.Id;

            var amount = 789;
            payment.Amount = amount;

            Assert.AreEqual(id, payment.Id);
            Assert.AreEqual(amount, payment.Amount);
        }
コード例 #4
0
        public void SaveToDatabase_MultipleRecurringPayment_AllSaved()
        {
            var payment1 = new RecurringPayment
            {
                Note = "MultiRecPayment1"
            };

            var payment2 = new RecurringPayment
            {
                Note = "MultiRecPayment2"
            };

            var dataAccess = new RecurringPaymentDataAccess(connectionCreator);
            dataAccess.SaveItem(payment1);
            dataAccess.SaveItem(payment2);

            var resultList = dataAccess.LoadList();

            Assert.IsTrue(resultList.Any(x => x.Id == payment1.Id && x.Note == payment1.Note));
            Assert.IsTrue(resultList.Any(x => x.Id == payment2.Id && x.Note == payment2.Note));
        }
コード例 #5
0
        /// <summary>
        ///     Checks if the recurring payment is up for a repetition based on the passed Payment
        /// </summary>
        /// <param name="recurringPayment">Recurring payment to check.</param>
        /// <param name="relatedPayment">Payment to compare.</param>
        /// <returns>True or False if the payment have to be repeated.</returns>
        public static bool CheckIfRepeatable(RecurringPayment recurringPayment, Payment relatedPayment)
        {
            if (!relatedPayment.IsCleared)
            {
                return false;
            }

            switch (recurringPayment.Recurrence)
            {
                case (int) PaymentRecurrence.Daily:
                    return DateTime.Today.Date != relatedPayment.Date.Date;

                case (int) PaymentRecurrence.DailyWithoutWeekend:
                    return DateTime.Today.Date != relatedPayment.Date.Date
                           && DateTime.Today.DayOfWeek != DayOfWeek.Saturday
                           && DateTime.Today.DayOfWeek != DayOfWeek.Sunday;

                case (int) PaymentRecurrence.Weekly:
                    var daysWeekly = DateTime.Now - relatedPayment.Date;
                    return daysWeekly.Days >= 7;

                case (int) PaymentRecurrence.Biweekly:
                    var daysBiweekly = DateTime.Now - relatedPayment.Date;
                    return daysBiweekly.Days >= 14;

                case (int) PaymentRecurrence.Monthly:
                    return DateTime.Now.Month != relatedPayment.Date.Month;

                case (int) PaymentRecurrence.Yearly:
                    return (DateTime.Now.Year != relatedPayment.Date.Year
                            && DateTime.Now.Month >= relatedPayment.Date.Month)
                           || DateTime.Now.Year - relatedPayment.Date.Year > 1;

                default:
                    return false;
            }
        }
コード例 #6
0
        public void SaveToDatabase_CreateAndUpdateRecurringPayment_CorrectlyUpdated()
        {
            var firstAmount = 5555555;
            var secondAmount = 222222222;

            var payment = new RecurringPayment
            {
                Amount = firstAmount
            };

            var dataAccess = new RecurringPaymentDataAccess(connectionCreator);
            dataAccess.SaveItem(payment);

            Assert.AreEqual(firstAmount, dataAccess.LoadList().FirstOrDefault(x => x.Id == payment.Id).Amount);

            payment.Amount = secondAmount;
            dataAccess.SaveItem(payment);

            var categories = dataAccess.LoadList();
            Assert.IsFalse(categories.Any(x => x.Amount == firstAmount));
            Assert.AreEqual(secondAmount, categories.First(x => x.Id == payment.Id).Amount);
        }
コード例 #7
0
        public void DeleteFromDatabase_RecurringPaymentToDelete_CorrectlyDelete()
        {
            var payment = new RecurringPayment
            {
                Note = "paymentToDelete"
            };

            var dataAccess = new RecurringPaymentDataAccess(connectionCreator);
            dataAccess.SaveItem(payment);

            Assert.IsTrue(dataAccess.LoadList(x => x.Id == payment.Id).Any());

            dataAccess.DeleteItem(payment);
            Assert.IsFalse(dataAccess.LoadList(x => x.Id == payment.Id).Any());
        }
コード例 #8
0
        public void RemoveRecurringForPayments(RecurringPayment recurringPayment)
        {
            try
            {
                var relatedPayment = paymentRepository
                    .Data
                    .Where(x => x.IsRecurring && x.RecurringPaymentId == recurringPayment.Id);

                foreach (var payment in relatedPayment)
                {
                    payment.IsRecurring = false;
                    payment.RecurringPaymentId = 0;
                    paymentRepository.Save(payment);
                }
            }
            catch (Exception ex)
            {
                Mvx.Trace(MvxTraceLevel.Error, ex.Message);
            }
        }
コード例 #9
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();
        }
コード例 #10
0
        public void CheckIfRepeatable_Yearly_ValidatedRecurrence()
        {
            var account = new Account {Id = 2};

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

            RecurringPaymentHelper.CheckIfRepeatable(recurringPayment,
                new Payment {Date = DateTime.Today.AddDays(-380), IsCleared = true})
                .ShouldBeTrue();
        }
コード例 #11
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));
        }