示例#1
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var loanTerm = LoanTerm.GetLoanTerm(TermYears);

            LoanApplication.Term = loanTerm;

            var result = _loanProcessingService.ProcessLoan(LoanApplication);

            _resultRepository.SaveLoanApplicationResult(result);


            return(RedirectToPage($"./LoanApplicationResult", new { id = result.ResultId }));
        }
示例#2
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                LoanTerms = LoanTerm.LoanTerms.Values
                            .OrderBy(t => t.Years)
                            .ToSelectList(t => t.Years.ToString(), t => t.Name);

                return(Page());
            }

            LoanApplication.Term = LoanTerm.GetLoanTerm(TermYears);

            var result = _loanProcessingService.ProcessLoan(LoanApplication);

            _resultRepository.SaveLoanApplicationResult(result);

            return(RedirectToPage($"./LoanApplicationResult", new { id = result.ResultId }));
        }
示例#3
0
        public void TestLoanApprovedForHighCreditScore()
        {
            var application = new LoanApplication()
            {
                FirstName    = "John",
                LastName     = "Doe",
                AnnualIncome = 50_000,
                CreditScore  = 77,
                LoanAmount   = 250_000,
                Term         = LoanTerm.YEARS_30
            };
            LoanProcessingService service = new LoanProcessingService(Rates,
                                                                      new CreditScoreLoanApprovalRule(),
                                                                      new LoanSizeLoanApprovalRule()
                                                                      );

            // Act
            var result = service.ProcessLoan(application);

            Assert.IsTrue(result.Approved);
        }
示例#4
0
        public void TestLoanHasCorrectInterestRate()
        {
            // Arrange
            var application = new LoanApplication()
            {
                FirstName    = "John",
                LastName     = "Doe",
                AnnualIncome = 50_000,
                CreditScore  = 73,
                LoanAmount   = 250_000,
                Term         = LoanTerm.YEARS_30
            };
            LoanProcessingService service = new LoanProcessingService(Rates,
                                                                      new CreditScoreLoanApprovalRule(),
                                                                      new LoanSizeLoanApprovalRule()
                                                                      );

            // Act
            var result = service.ProcessLoan(application);

            // Assert
            Assert.IsNotNull(result.InterestRate, "This loan should be approved and have an interest rate");
            Assert.AreEqual(0.0625, result.InterestRate.Value);
        }
示例#5
0
        public void TestLoansOverOneMillionDollarsShouldBeDenied()
        {
            // Arrange
            var application = new LoanApplication()
            {
                FirstName    = "John",
                LastName     = "Doe",
                AnnualIncome = 250_000,
                CreditScore  = 95,
                LoanAmount   = 1_000_001,
                Term         = LoanTerm.YEARS_30
            };
            LoanProcessingService service = new LoanProcessingService(Rates,
                                                                      new CreditScoreLoanApprovalRule(),
                                                                      new LoanSizeLoanApprovalRule()
                                                                      );

            // Act
            var result = service.ProcessLoan(application);

            // Assert
            Assert.IsFalse(result.Approved);
        }
    }
示例#6
0
        public void TestLoanHasCorrectPaymentCalculated()
        {
            // Arrange
            var application = new LoanApplication()
            {
                FirstName    = "John",
                LastName     = "Doe",
                AnnualIncome = 50_000,
                CreditScore  = 73,
                LoanAmount   = 250_000,
                Term         = LoanTerm.YEARS_30
            };
            LoanProcessingService service = new LoanProcessingService(Rates,
                                                                      new CreditScoreLoanApprovalRule(),
                                                                      new LoanSizeLoanApprovalRule()
                                                                      );

            // Act
            var result = service.ProcessLoan(application);

            // Assert
            Assert.IsNotNull(result.MonthlyPayment);
            Assert.AreEqual(1539.29, result.MonthlyPayment.Value);
        }