public void GetLoanSummary_ReturnsNotNull() { LoanSummaryController controller = new LoanSummaryController(); LoanSummary result = controller.GetLoanSummary(50000m, 19); Assert.IsNotNull(result); }
private List <PaymentScheduleItem> CalculatePayments(LoanSummary summary, IEnumerable <DateTime> paymentDates) { List <PaymentScheduleItem> scheduler = new List <PaymentScheduleItem>(); var creditAmount = summary.FullPrice - summary.Deposit; var paymentRate = Math.Round((creditAmount / summary.LoanLenght), 2); foreach (DateTime date in paymentDates) { scheduler.Add(new PaymentScheduleItem { PaymentDate = date, PaymentAmount = paymentRate }); } var mathRoundDifference = creditAmount - scheduler.Sum(x => x.PaymentAmount); scheduler[summary.LoanLenght - 1].PaymentAmount += (mathRoundDifference); scheduler[0].PaymentAmount += (summary.ArrangmentFee == null ? 0 : Convert.ToDecimal(summary.ArrangmentFee)); scheduler[summary.LoanLenght - 1].PaymentAmount += (summary.CompletionFee == null ? 0 : Convert.ToDecimal(summary.CompletionFee)); return(scheduler); }
public void GetLoanSummary_TotalInterestIsCorrect() { LoanCalculationService service = new LoanCalculationService(); LoanSummary result = service.GetLoanSummary(50000m, 19); Assert.AreEqual(result.TotalInterest, 5016.0m); }
public void GetLoanSummary_WeeklyRepaymentIsCorrect() { LoanCalculationService service = new LoanCalculationService(); LoanSummary result = service.GetLoanSummary(50000m, 19); Assert.AreEqual(result.WeeklyRepayment, 1058.0m); }
public async Task <LoanDetails> CalculateLoan(LoanSummary requestSummary) { var paymentDates = GetPaymentSchedulerDates(requestSummary.DeliveryDate, requestSummary.LoanLenght, DayOfWeek.Monday); return(new LoanDetails { Payments = await Task.Run <List <PaymentScheduleItem> >(() => CalculatePayments(requestSummary, paymentDates)), Summary = requestSummary }); }
public LoanSummary GetLoanSummary(LoanInformation loanInformation) { var loanSummary = new LoanSummary { WeeklyRepayment = PaymentHelpers.GetPayment(loanInformation.Amount, loanInformation.NumberOfPayments, loanInformation.APR) }; loanSummary.TotalRepaid = loanSummary.WeeklyRepayment * loanInformation.NumberOfPayments; loanSummary.TotalInterest = loanSummary.TotalRepaid - loanInformation.Amount; return(loanSummary); }
private const int totalPayments = 52; // Number of weekly payments #region Public methods public LoanSummary GetLoanSummary(decimal amount, int apr) { ValidateAmount(amount); ValidateApr(apr); var repayment = Math.Round(GetInstallmentAmount(amount, totalPayments, apr), 0, MidpointRounding.AwayFromZero); var totalRepaid = repayment * totalPayments; var totalInterest = totalRepaid - amount; var loanSummary = new LoanSummary(repayment, totalRepaid, totalInterest); return(loanSummary); }
public void DoesCalculeteLoanReturnsTheSameServiceDetailsAsPassedToTheMethodTest() { var summary = new LoanSummary() { ArrangmentFee = 88, CompletionFee = 20, Deposit = 150, FullPrice = 2000, LoanLenght = 12, DeliveryDate = new DateTime(2020, 1, 1) }; var loanDetails = services.CalculateLoan(summary).Result; Assert.AreEqual(summary, loanDetails.Summary); }
public LoanSummary GetLoanSummary(Loan loan) { var totalLoanAmount = GetTotalLoanAmount(loan); var financeMonths = loan.FinanceMonths; var standardPaymentAmount = GetStandardPaymentAmount(totalLoanAmount, financeMonths); var initialPaymentAmount = GetInitialPaymentAmount(standardPaymentAmount, loan.LoanFee); var finalPaymentAmount = GetFinalPaymentAmount(standardPaymentAmount, loan.LoanFee); var ls = new LoanSummary() { Loan = loan, TotalLoanAmount = totalLoanAmount, TotalMonths = financeMonths, PaymentFrequency = PaymentFrequency.Monthly, InitialPaymentAmount = initialPaymentAmount, StandardMonthlyPaymentAmount = standardPaymentAmount, FinalPaymentAmount = finalPaymentAmount }; return(ls); }
public LoanPaymentSchedule GetPaymentSchedule(Loan loan, LoanSummary summary) { var payments = new List <LoanPayment>(); var deliveryYear = loan.DeliveryDate.Year; var deliveryMonth = loan.DeliveryDate.Month; var nextPaymentMonth = GetNextPaymentMonth(deliveryMonth); var nextPaymentYear = GetNextPaymentYear(deliveryMonth, deliveryYear); for (int i = 1; i <= loan.FinanceMonths; i++) { var lp = new LoanPayment(); lp.MonthNumber = i; if (i == 1) { lp.PaymentAmount = summary.InitialPaymentAmount; } else if (i == loan.FinanceMonths) { lp.PaymentAmount = summary.FinalPaymentAmount; } else { lp.PaymentAmount = summary.StandardMonthlyPaymentAmount; } var nextPaymentDate = GetFirstMondayOfMonth(nextPaymentYear, nextPaymentMonth); lp.PaymentDate = nextPaymentDate; nextPaymentYear = GetNextPaymentYear(nextPaymentMonth, nextPaymentYear); nextPaymentMonth = GetNextPaymentMonth(nextPaymentMonth); payments.Add(lp); } var lps = new LoanPaymentSchedule(); lps.LoanPayments = payments; return(lps); }
public void Setup() { _loan = new Loan() { DeliveryDate = new System.DateTime(2019, 05, 02), Deposit = 500, FinanceMonths = 24, VehiclePrice = 13999, LoanFee = new Fee() { ArrangementFee = 80, CompletionFee = 20 } }; _loanSummary = new LoanSummary() { Loan = _loan, TotalLoanAmount = 13599, TotalMonths = 24, PaymentFrequency = PaymentFrequency.Monthly, InitialPaymentAmount = 646.62m, StandardMonthlyPaymentAmount = 566.62m, FinalPaymentAmount = 586.62m }; _loanPayments = new List <LoanPayment>() { new LoanPayment() { MonthNumber = 1, PaymentDate = new System.DateTime(2019, 06, 03), PaymentAmount = _loanSummary.InitialPaymentAmount }, new LoanPayment() { MonthNumber = 2, PaymentDate = new System.DateTime(2019, 07, 01), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 3, PaymentDate = new System.DateTime(2019, 08, 05), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 4, PaymentDate = new System.DateTime(2019, 09, 02), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 5, PaymentDate = new System.DateTime(2019, 10, 07), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 6, PaymentDate = new System.DateTime(2019, 11, 04), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 7, PaymentDate = new System.DateTime(2019, 12, 02), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 8, PaymentDate = new System.DateTime(2020, 01, 06), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 9, PaymentDate = new System.DateTime(2020, 02, 03), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 10, PaymentDate = new System.DateTime(2020, 03, 02), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 11, PaymentDate = new System.DateTime(2020, 04, 06), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 12, PaymentDate = new System.DateTime(2020, 05, 04), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 13, PaymentDate = new System.DateTime(2020, 06, 01), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 14, PaymentDate = new System.DateTime(2020, 07, 06), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 15, PaymentDate = new System.DateTime(2020, 08, 03), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 16, PaymentDate = new System.DateTime(2020, 09, 07), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 17, PaymentDate = new System.DateTime(2020, 10, 05), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 18, PaymentDate = new System.DateTime(2020, 11, 02), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 19, PaymentDate = new System.DateTime(2020, 12, 07), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 20, PaymentDate = new System.DateTime(2021, 01, 04), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 21, PaymentDate = new System.DateTime(2021, 02, 01), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 22, PaymentDate = new System.DateTime(2021, 03, 01), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 23, PaymentDate = new System.DateTime(2021, 04, 05), PaymentAmount = _loanSummary.StandardMonthlyPaymentAmount }, new LoanPayment() { MonthNumber = 24, PaymentDate = new System.DateTime(2021, 05, 03), PaymentAmount = _loanSummary.FinalPaymentAmount } }; _loanPaymentSchedule = new LoanPaymentSchedule() { LoanPayments = _loanPayments }; }