Ejemplo n.º 1
0
        public void Affordability_check_returns_value(AffordabilityRating engineResult)
        {
            // Arrange

            var loanDecision = new LoanDecision();

            var request = new CheckAffordability
            {
                LoanApplication = new LoanApplication(),
                LoanDecision    = loanDecision,
            };

            var mockAffordabilityVerifier = new Mock <IAffordabilityEngine>(MockBehavior.Strict);

            mockAffordabilityVerifier.Setup(m => m.Calculate(It.IsNotNull <LoanApplication>())).Returns(engineResult);

            var affordabilityCheck = new CheckAffordabilityHandler(mockAffordabilityVerifier.Object);

            // Act

            var response = affordabilityCheck.Handle(request);

            // Assert

            Assert.Equal(engineResult, response.AffordabilityRating);
            Assert.Equal(engineResult, loanDecision.AffordabilityRating);
        }
Ejemplo n.º 2
0
        protected override void ConfigureDefinition(FlowDefinition <MakeLoanApplicationDecision, MakeLoanApplicationDecision.Response> flowDefinition)
        {
            flowDefinition

            .Do("InitialiseNewDecision", InitialiseNewLoanDecision.NewDefinition())

            // ------------------------------------------------------------------------------------------------

            .Do("CheckEligibility", CheckEligibility.NewDefinition())
            .Check("IsEligible", FlowValueDecision <bool?> .NewDefinition()
                   .BindInput(rq => rq.SwitchValue, nameof(CheckEligibility.Response.IsEligible)))
            .When(false).Goto("SetResultToDecline")
            .When(true).Goto("CheckAffordability")
            .Else().Unhandled()

            // ------------------------------------------------------------------------------------------------

            .Do("CheckAffordability", CheckAffordability.NewDefinition())
            .Check("AffordabilityRating", FlowValueDecision <AffordabilityRating?> .NewDefinition()
                   .BindInput(rq => rq.SwitchValue, nameof(CheckAffordability.Response.AffordabilityRating)))
            .When(AffordabilityRating.Fair).Goto("SetResultToRefer")
            .When(AffordabilityRating.Poor).Goto("SetResultToDecline")
            .When(AffordabilityRating.Good).Goto("CheckIdentity")
            .Else().Unhandled()

            // ------------------------------------------------------------------------------------------------

            .Do("CheckIdentity", CheckIdentity.NewDefinition())
            .Check("IdentityCheckResult", FlowValueDecision <IdentityCheckResult?> .NewDefinition()
                   .BindInput(rq => rq.SwitchValue, nameof(CheckIdentity.Response.IdentityCheckResult)))
            .When(IdentityCheckResult.ServiceUnavailable).Goto("SetResultToRefer")
            .When(IdentityCheckResult.IdentityNotFound).Goto("SetResultToDecline")
            .When(IdentityCheckResult.IdentityFound).Goto("SetResultToAccept")
            .Else().Unhandled()

            // ------------------------------------------------------------------------------------------------

            .Do("SetResultToAccept", SetLoanDecisionResult.NewDefinition()
                .SetValue(rq => rq.Result, LoanDecisionResult.Accept))
            .Goto("SaveDecision")

            .Do("SetResultToRefer", SetLoanDecisionResult.NewDefinition()
                .SetValue(rq => rq.Result, LoanDecisionResult.Refer))
            .Goto("SaveDecision")

            .Do("SetResultToDecline", SetLoanDecisionResult.NewDefinition()
                .SetValue(rq => rq.Result, LoanDecisionResult.Decline))
            .Goto("SaveDecision")

            // ------------------------------------------------------------------------------------------------

            .Do("SaveDecision", CreateLoanDecision.NewDefinition())

            .Check("LoanDecisionResult", FlowValueDecision <LoanDecisionResult?> .NewDefinition()
                   .BindInput(rq => rq.SwitchValue, nameof(SetLoanDecisionResult.Response.Result)))
            .When(LoanDecisionResult.Decline).Goto("PostDeclineActions")
            .When(LoanDecisionResult.Refer).Goto("PostReferActions")
            .When(LoanDecisionResult.Accept).Goto("PostAcceptActions")
            .Else().Unhandled()

            // ------------------------------------------------------------------------------------------------

            .Label("PostAcceptActions")
            .Do("SendAcceptConfirmationEmail", SendEmail.NewDefinition()
                .SetValue(rq => rq.TemplateName, "AcceptConfirmation")
                .BindInput(rq => rq.EmailAddress,
                           nameof(MakeLoanApplicationDecision.LoanApplication), (LoanApplication la) => la.EmailAddress)
                .BindInputs(rq => rq.DataObjects,
                            nameof(MakeLoanApplicationDecision.LoanApplication),
                            nameof(InitialiseNewLoanDecision.Response.LoanDecision))
                .BindInput(rq => rq.ParentId,
                           nameof(InitialiseNewLoanDecision.Response.LoanDecision), (LoanDecision ld) => ld.Id))
            .End()

            // ------------------------------------------------------------------------------------------------

            .Label("PostReferActions")
            .Do("SendReferNotificationEmail", SendEmail.NewDefinition()
                .SetValue(rq => rq.TemplateName, "ReferNotification")
                .BindInput(rq => rq.EmailAddress,
                           nameof(MakeLoanApplicationDecision.LoanApplication), (LoanApplication la) => la.EmailAddress)
                .BindInputs(rq => rq.DataObjects,
                            nameof(MakeLoanApplicationDecision.LoanApplication),
                            nameof(InitialiseNewLoanDecision.Response.LoanDecision))
                .BindInput(rq => rq.ParentId,
                           nameof(InitialiseNewLoanDecision.Response.LoanDecision), (LoanDecision ld) => ld.Id))
            .Do("RaiseLoanReferredEvent", RaiseLoanDecisionReferredEvent.NewDefinition())
            .End()

            // ------------------------------------------------------------------------------------------------

            .Label("PostDeclineActions")
            .Do("SendDeclineConfirmationEmail", SendEmail.NewDefinition()
                .SetValue(rq => rq.TemplateName, "DeclineConfirmation")
                .BindInput(rq => rq.EmailAddress,
                           nameof(MakeLoanApplicationDecision.LoanApplication), (LoanApplication la) => la.EmailAddress)
                .BindInputs(rq => rq.DataObjects,
                            nameof(MakeLoanApplicationDecision.LoanApplication),
                            nameof(InitialiseNewLoanDecision.Response.LoanDecision))
                .BindInput(rq => rq.ParentId,
                           nameof(InitialiseNewLoanDecision.Response.LoanDecision), (LoanDecision ld) => ld.Id))
            .End();
        }