public void GetLoanSummary()
        {
            // Arrange
            LoanController controller = new LoanController(new Services.LoanService());

            // Act
            LoanSummaryDto result = controller.GetLoanSummary(50000, 19);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1058, result.WeeklyPayment);
            Assert.AreEqual(55016, result.TotalRepaid);
            Assert.AreEqual(5016, result.TotalInterest);
        }
Example #2
0
        public LoanSummaryDto GetLoanSummary(double amount, double apr, int period = 52)
        {
            LoanSummaryDto result = new LoanSummaryDto();

            double interest       = apr;
            double rateOfInterest = interest / (period * 100);
            double loanAmount     = amount;
            double weeklyRePaid   = Math.Round(loanAmount * (rateOfInterest * Math.Pow((1 + rateOfInterest), period)) /
                                               (Math.Pow((1 + rateOfInterest), period) - 1));

            double totalRepaid   = weeklyRePaid * period;
            double totalInterest = totalRepaid - loanAmount;

            result = new LoanSummaryDto
            {
                TotalInterest = totalInterest,
                TotalRepaid   = totalRepaid,
                WeeklyPayment = weeklyRePaid
            };


            return(result);
        }