public void ShouldCorrectlyCalculatePaymentsPlan() { var loanAmount = 120000M; var loanYearsDuration = 10; var payments = _loanService.CalculateLoanPayments(_defaultLoan.Id, loanAmount, loanYearsDuration); Assert.AreEqual(1100M, payments.First().Value); Assert.AreEqual(1, payments.First().MonthNumber); Assert.AreEqual(1090M, payments.Skip(12).First().Value); Assert.AreEqual(13, payments.Skip(12).First().MonthNumber); Assert.AreEqual(1000.83M, payments.Last().Value); Assert.AreEqual(120, payments.Count()); }
public ActionResult <IEnumerable <LoanPayment> > CalculateLoan(LoanCalculateRequest request) { _logger.LogInformation($"Received request to calculate loan payments"); IEnumerable <LoanPayment> payments; try { payments = _loanService.CalculateLoanPayments(request.LoanId, request.LoanAmount, request.LoanYearsDuration); } catch (ArgumentException) { return(BadRequest()); } catch (NotFoundException) { return(NotFound()); } return(Ok(payments)); }