Example #1
0
        public void CustomerIsNotARegisteredDebtor_CustomerNotADebtor_IsSatisfied()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithIdentifier("71041864667"))
                              .Build();

            var rule            = new CustomerIsNotARegisteredDebtor(new DebtorRegistryMock());
            var ruleCheckResult = rule.IsSatisfiedBy(application);

            Assert.True(ruleCheckResult);
        }
Example #2
0
        public void WhenAnyRuleIsNotSatisfied_ScoringResult_IsRed()
        {
            var application = new LoanApplicationBuilder()
                              .WithLoan(loan => loan.WithNumberOfYears(20).WithAmount(400_000M).WithInterestRate(1M))
                              .WithCustomer(customer => customer.WithIncome(4_000M))
                              .Build();

            var score = scoringRulesFactory.DefaultSet.Evaluate(application);

            Assert.Equal(ApplicationScore.Red, score.Score);
        }
        public void NewApplication_IsCreatedIn_NewStatus_AndNullScore()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Build();

            LoanApplicationAssert.That(application)
            .IsInStatus(LoanApplicationStatus.New)
            .ScoreIsNull();
        }
Example #4
0
        public void CustomerIncome15PercentLowerThenOfInstallment_InstallmentAmountMustBeLowerThen15PercentOfCustomerIncome_IsNotSatisfied()
        {
            var application = new LoanApplicationBuilder()
                              .WithLoan(loan => loan.WithNumberOfYears(20).WithAmount(400_000M).WithInterestRate(1M))
                              .WithCustomer(customer => customer.WithIncome(4_000M))
                              .Build();

            var rule            = new InstallmentAmountMustBeLowerThen15PercentOfCustomerIncome();
            var ruleCheckResult = rule.IsSatisfiedBy(application);

            Assert.False(ruleCheckResult);
        }
Example #5
0
        public void CustomerOlderThan65AtEndOfLoan_CustomerAgeAtTheDateOfLastInstallmentMustBeBelow65_IsNotSatisfied()
        {
            var application = new LoanApplicationBuilder()
                              .WithLoan(loan => loan.WithNumberOfYears(20))
                              .WithCustomer(customer => customer.WithAge(46))
                              .Build();

            var rule            = new CustomerAgeAtTheDateOfLastInstallmentMustBeBelow65();
            var ruleCheckResult = rule.IsSatisfiedBy(application);

            Assert.False(ruleCheckResult);
        }
Example #6
0
        public void PropertyValueLowerThanLoan_LoanAmountMustBeLowerThanPropertyValue_IsNotSatisfied()
        {
            var application = new LoanApplicationBuilder()
                              .WithProperty(prop => prop.WithValue(750_000M))
                              .WithLoan(loan => loan.WithAmount(800_000M))
                              .Build();

            var rule            = new LoanAmountMustBeLowerThanPropertyValue();
            var ruleCheckResult = rule.IsSatisfiedBy(application);

            Assert.False(ruleCheckResult);
        }
Example #7
0
        public void WhenAllRulesAreSatisfied_ScoringResult_IsGreen()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Build();

            var score = scoringRulesFactory.DefaultSet.Evaluate(application);

            Assert.Equal(ApplicationScore.Green, score.Score);
        }
        public void InvalidApplication_EvaluationScore_IsRed_And_StatusIsRejected()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(55).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Build();

            application.Evaluate(scoringRulesFactory.DefaultSet);

            LoanApplicationAssert.That(application)
            .IsInStatus(LoanApplicationStatus.Rejected)
            .ScoreIs(ApplicationScore.Red);
        }
        public void LoanApplication_WithoutScore_CannotBeAccepted()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .NotEvaluated()
                              .Build();

            var user = new OperatorBuilder().WithLogin("admin").Build();
            var ex   = Assert.Throws <ApplicationException>(() => application.Accept(user));

            Assert.Equal("Cannot accept application before scoring", ex.Message);
        }
        public void LoanApplication_Accepted_CannotBeRejected()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Evaluated()
                              .Accepted()
                              .Build();

            var user = new OperatorBuilder().WithLogin("admin").Build();
            var ex   = Assert.Throws <ApplicationException>(() => application.Reject(user));

            Assert.Equal("Cannot reject application that is already accepted or rejected", ex.Message);
        }
        public void LoanApplication_WithoutScore_CanBeRejected()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .NotEvaluated()
                              .Build();

            var user = new OperatorBuilder().WithLogin("admin").Build();

            application.Reject(user);

            LoanApplicationAssert.That(application)
            .IsInStatus(LoanApplicationStatus.Rejected)
            .ScoreIsNull();
        }
        public void LoanApplication_InStatusNew_EvaluatedGreen_OperatorDoesNotHaveCompetenceLevel_CannotBeAccepted()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Evaluated()
                              .Build();

            var user = new OperatorBuilder()
                       .WithLogin("admin")
                       .WithCompetenceLevel(100_000M)
                       .Build();

            var ex = Assert.Throws <ApplicationException>(() => application.Accept(user));

            Assert.Equal("Operator does not have required competence level to accept application", ex.Message);
        }
        public void LoanApplication_InStatusNew_EvaluatedGreen_OperatorHasCompetenceLevel_CanBeAccepted()
        {
            var application = new LoanApplicationBuilder()
                              .WithCustomer(customer => customer.WithAge(25).WithIncome(15_000M))
                              .WithLoan(loan => loan.WithAmount(200_000).WithNumberOfYears(25).WithInterestRate(1.1M))
                              .WithProperty(prop => prop.WithValue(250_000M))
                              .Evaluated()
                              .Build();

            var user = new OperatorBuilder()
                       .WithLogin("admin")
                       .WithCompetenceLevel(1_000_000M)
                       .Build();

            application.Accept(user);

            LoanApplicationAssert.That(application)
            .IsInStatus(LoanApplicationStatus.Accepted)
            .ScoreIs(ApplicationScore.Green);
        }