コード例 #1
0
        protected override void ConfigureDefinition(FlowDefinition <DecisionWithEndFlowRequest, DecisionWithEndFlowResponse> flowDefinition)
        {
            var switchValueDecision = FlowValueDecision <string> .NewDefinition()
                                      .BindInput(rq => rq.SwitchValue, nameof(DecisionWithEndFlowRequest.StringValue));

            var setOutputToX = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "X")
                               .BindOutput(rs => rs.Output, nameof(DecisionWithEndFlowResponse.BranchValue));

            var setOutputToY = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "Y")
                               .BindOutput(rs => rs.Output, nameof(DecisionWithEndFlowResponse.BranchValue));

            var setOutputToZ = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "Z")
                               .BindOutput(rs => rs.Output, nameof(DecisionWithEndFlowResponse.BranchValue));

            flowDefinition
            .Do("Set_output_to_X", setOutputToX)

            .Check("Switch_value_1", switchValueDecision)
            .When("A").End()
            .When("B").Goto("Set_output_to_Y")
            .Else().Continue()

            .Do("Set_output_to_Y", setOutputToY)

            .Check("Switch_value_2", switchValueDecision)
            .When("C").Goto("Set_output_to_Z")
            .Else().End()

            .Do("Set_output_to_Z", setOutputToZ)
            ;
        }
コード例 #2
0
        protected override void ConfigureDefinition(FlowDefinition <SubPropertyBindingsFlowRequest, SubPropertyBindingsFlowResponse> flowDefinition)
        {
            flowDefinition

            .Check("Decision_1", FlowValueDecision <int?> .NewDefinition()
                   .BindInput(rq => rq.SwitchValue, "StringValue1", (string s) => s.Length))
            .When(0).End()
            .Else().Continue()

            .Check("Decision_2",
                   FlowValueDecision <int?> .NewDefinition()
                   .BindInput(rq => rq.SwitchValue, "StringValue2", (string s) => s.Length))
            .When(0).End()
            .Else().Continue()

            .Do("Activity_1",
                new FlowActivityDefinition <SubPropertyBindingsActivityRequest, SubPropertyBindingsActivityResponse>()
                .BindInput(rq => rq.IntValue, "StringValue1", (string s) => s.Length)
                .BindOutput(rs => rs.IntValue, "StringValue1", i => i.ToString()))

            .Do("Activity_2",
                new FlowActivityDefinition <SubPropertyBindingsActivityRequest, SubPropertyBindingsActivityResponse>()
                .BindInput(rq => rq.IntValue, "StringValue2", (string s) => s.Length)
                .BindOutput(rs => rs.IntValue, "StringValue2", i => i.ToString()));
        }
コード例 #3
0
        protected override void ConfigureDefinition(FlowDefinition <MockedDecisionFlowRequest, MockedDecisionFlowResponse> flowDefinition)
        {
            var intValue = FlowValueDecision <int?> .NewDefinition()
                           .BindInput(rq => rq.SwitchValue, nameof(MockedDecisionFlowRequest.IntValue));

            var setOutputToX = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "X")
                               .BindOutput(rs => rs.Output, nameof(MockedDecisionFlowResponse.BranchValue));

            var setOutputToY = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "Y")
                               .BindOutput(rs => rs.Output, nameof(MockedDecisionFlowResponse.BranchValue));

            var setOutputToZ = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "Z")
                               .BindOutput(rs => rs.Output, nameof(MockedDecisionFlowResponse.BranchValue));

            flowDefinition
            .Check("Int_value", intValue)
            .When(1).Goto("Set_output_to_X")
            .When(2).Goto("Set_output_to_Y")
            .Else().Goto("Set_output_to_Z")

            .Do("Set_output_to_X", setOutputToX)
            .End()

            .Do("Set_output_to_Y", setOutputToY)
            .End()

            .Do("Set_output_to_Z", setOutputToZ)
            .End();
        }
コード例 #4
0
ファイル: MatchDecisionFlow.cs プロジェクト: andybalham/FlowR
        protected override void ConfigureDefinition(FlowDefinition <MatchDecisionFlowRequest, MatchDecisionFlowResponse> flowDefinition)
        {
            #region Definitions

            var intValueDecision = FlowValueDecision <int?> .NewDefinition()
                                   .BindInput(rq => rq.SwitchValue, nameof(MatchDecisionFlowRequest.IntValue));

            var stringValueDecision = FlowValueDecision <string> .NewDefinition()
                                      .BindInput(rq => rq.SwitchValue, nameof(MatchDecisionFlowRequest.StringValue));

            var setOutputToX = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "X")
                               .BindOutput(rs => rs.Output, nameof(MatchDecisionFlowResponse.BranchValue));

            var setOutputToY = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                               .SetValue(rq => rq.OutputValue, "Y")
                               .BindOutput(rs => rs.Output, nameof(MatchDecisionFlowResponse.BranchValue));

            var setOutputToZa = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                                .SetValue(rq => rq.OutputValue, "ZA")
                                .BindOutput(rs => rs.Output, nameof(MatchDecisionFlowResponse.BranchValue));

            var setOutputToZz = new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                                .SetValue(rq => rq.OutputValue, "ZZ")
                                .BindOutput(rs => rs.Output, nameof(MatchDecisionFlowResponse.BranchValue));

            #endregion

            flowDefinition
            .Check("Int_value", intValueDecision)
            .When(1).Goto("Set_output_to_X")
            .When(2, 3).Goto("Set_output_to_Y")
            .Else().Goto("String_value")

            .Do("Set_output_to_X", setOutputToX)
            .End()

            .Do("Set_output_to_Y", setOutputToY)
            .End()

            .Check("String_value", stringValueDecision)
            .When("A").Goto("Set_output_to_ZA")
            .Else().Continue()

            .Do("Set_output_to_ZZ", setOutputToZz)
            .End()

            .Do("Set_output_to_ZA", setOutputToZa);
        }
コード例 #5
0
        protected override void ConfigureDefinition(FlowDefinition <MultipleMatchDecisionFlowRequest, MultipleMatchDecisionFlowResponse> flowDefinition)
        {
            #region Definitions

            var intValueDecision = FlowValueDecision <int?> .NewDefinition()
                                   .BindInput(rq => rq.SwitchValue, nameof(MatchDecisionFlowRequest.IntValue));

            #endregion

            flowDefinition
            .Check("Int_value", intValueDecision)
            .When(1).End()
            .When(1, 2, 3).End()
            .Else().End();
        }
コード例 #6
0
        public void Can_validate_unknown_steps()
        {
            var flowDefinition = new FlowDefinition <TestFlowRequest, TestFlowResponse>()
                                 .Check("Check", FlowValueDecision <int?> .NewDefinition())
                                 .When(444).Goto("UnknownActivity1")
                                 .Else().Goto("UnknownActivity2")
                                 .Goto("UnknownActivity3");

            var validationMessages = flowDefinition.Validate().ToList();

            Assert.Equal(3, validationMessages.Count);

            Assert.Contains(validationMessages, m => m.Contains("UnknownActivity1"));
            Assert.Contains(validationMessages, m => m.Contains("UnknownActivity2"));
            Assert.Contains(validationMessages, m => m.Contains("UnknownActivity3"));
        }
コード例 #7
0
        public void Can_validate_orphaned_steps()
        {
            var flowDefinition = new FlowDefinition <TestFlowRequest, TestFlowResponse>()
                                 .Do("Activity_1", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Check("Is_int_666", FlowValueDecision <int?> .NewDefinition())
                                 .When(666).Goto("Activity_3")
                                 .Else().Goto("Is_int_555")

                                 .Do("Orphan_activity_1", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Check("Is_int_555", FlowValueDecision <int?> .NewDefinition())
                                 .When(555).Goto("End_activity_label")
                                 .Else().Continue()

                                 .Do("Activity_2", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())
                                 .Goto("Activity_3")

                                 .Do("Orphan_activity_2", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Do("Activity_3", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())
                                 .End()

                                 .Do("Orphan_activity_3", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Label("End_activity_label")
                                 .Do("Activity_4", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>());

            var validationMessages = flowDefinition.Validate().ToList();

            Assert.NotEmpty(validationMessages);

            Assert.Contains(validationMessages, m => m.Contains("Orphan_activity_1"));
            Assert.Contains(validationMessages, m => m.Contains("Orphan_activity_2"));
            Assert.Contains(validationMessages, m => m.Contains("Orphan_activity_3"));

            Assert.DoesNotContain(validationMessages, m => m.Contains("Activity_1"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Activity_2"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Activity_3"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Activity_4"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Is_int_555"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Is_int_666"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("End_activity_label"));
        }
コード例 #8
0
        public void Can_accept_open_loops()
        {
            var flowDefinition = new FlowDefinition <TestFlowRequest, TestFlowResponse>()
                                 .Do("Activity_1", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())
                                 .Do("Activity_2", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Check("Is_int_666", FlowValueDecision <int?> .NewDefinition())
                                 .When(666).Goto("Activity_3")
                                 .Else().Continue()

                                 .Goto("Activity_1")

                                 .Do("Activity_3", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>());

            // TODO: Only allow loops if a flag is explicitly set
            var validationMessages = flowDefinition.Validate().ToList();

            Assert.Empty(validationMessages);
        }
コード例 #9
0
        public void Can_validate_closed_loops()
        {
            var flowDefinition = new FlowDefinition <TestFlowRequest, TestFlowResponse>()
                                 .Check("Is_int_444", FlowValueDecision <int?> .NewDefinition())
                                 .When(444).Goto("Activity_3")
                                 .Else().Continue()

                                 .Do("Activity_1", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())
                                 .Do("Activity_2", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Label("Label_1")

                                 .Check("Is_int_555", FlowValueDecision <int?> .NewDefinition())
                                 .When(555).Goto("Activity_1")
                                 .Else().Continue()

                                 .Check("Is_int_666", FlowValueDecision <int?> .NewDefinition())
                                 .When(666).Goto("Activity_2")
                                 .Else().Goto("Activity_1")

                                 .Goto("Activity_1")

                                 .Do("Activity_3", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>())

                                 .Check("Is_int_777", FlowValueDecision <int?> .NewDefinition())
                                 .When(666).Goto("Activity_3")
                                 .Else().Continue();

            var validationMessages = flowDefinition.Validate().ToList();

            Assert.Equal(5, validationMessages.Count);

            Assert.Contains(validationMessages, m => m.Contains("Activity_1"));
            Assert.Contains(validationMessages, m => m.Contains("Activity_2"));
            Assert.Contains(validationMessages, m => m.Contains("Label_1"));
            Assert.Contains(validationMessages, m => m.Contains("Is_int_555"));
            Assert.Contains(validationMessages, m => m.Contains("Is_int_666"));

            Assert.DoesNotContain(validationMessages, m => m.Contains("Is_int_444"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Activity_3"));
            Assert.DoesNotContain(validationMessages, m => m.Contains("Is_int_777"));
        }
コード例 #10
0
        public void Can_validate_duplicate_sets_and_bindings_in_definitions()
        {
            // TODO: Allow multiple output bindings as we could be setting multiple values from properties
            var flowDefinition = new FlowDefinition <TestFlowRequest, TestFlowResponse>()
                                 .Do("Set_value", new FlowActivityDefinition <SetStringFlowValueRequest, SetStringFlowValueResponse>()
                                     .SetValue(r => r.OutputValue, "Value1")
                                     .SetValue(r => r.OutputValue, "Value2")
                                     .BindOutput(r => r.Output, "Output1")
                                     .BindOutput(r => r.Output, "Output2"))

                                 .Check("Int_decision", FlowValueDecision <int?> .NewDefinition()
                                        .BindInput(r => r.SwitchValue, "Input1")
                                        .BindInput(r => r.SwitchValue, "Input2"))
                                 .Else().Continue();

            var validationMessages = flowDefinition.Validate().ToList();

            Assert.NotEmpty(validationMessages);

            Assert.Contains(validationMessages, m => m.Contains("property OutputValue"));
            Assert.Contains(validationMessages, m => m.Contains("property Output"));
            Assert.Contains(validationMessages, m => m.Contains("property SwitchValue"));
        }
コード例 #11
0
        protected override void ConfigureDefinition(FlowDefinition <TwentyQuestionsRequest, TwentyQuestionsResponse> flowDefinition)
        {
            flowDefinition

            .Do("AskHasLegs", QuestionRequest.NewDefinition()
                .SetValue(req => req.Question, "Does it have legs")
                .SetValue(req => req.Answers, new[] { "[Y]es", "[N]o" })
                .BindOutput(res => res.Answer, "HasLegs"))

            .Check("HasLegs", "Has legs?", FlowValueDecision <string> .NewDefinition()
                   .BindInput(req => req.SwitchValue, "HasLegs"))
            .When("Y").Goto("AskLegCount")
            .When("N").Goto("AskHasScales")
            .Else().Unhandled()

            .Do("AskLegCount", QuestionRequest.NewDefinition()
                .SetValue(req => req.Question, "How many legs does it have")
                .SetValue(req => req.Answers, new[] { "[2]", "[4]" })
                .BindOutput(res => res.Answer, "LegCount"))

            .Check("LegCount", "Leg count?", FlowValueDecision <string> .NewDefinition()
                   .BindInput(req => req.SwitchValue, "LegCount"))
            .When("2").Goto("AskCanFly")
            .When("4").Goto("AskEatsHay")
            .Else().Unhandled()

            .Do("AskCanFly", QuestionRequest.NewDefinition()
                .SetValue(req => req.Question, "Can it fly")
                .SetValue(req => req.Answers, new[] { "[Y]es", "[N]o" })
                .BindOutput(res => res.Answer, "CanFly"))

            .Check("CanFly", "Can fly?", FlowValueDecision <string> .NewDefinition()
                   .BindInput(req => req.SwitchValue, "CanFly"))
            .When("Y").Goto("GuessDuck")
            .When("N").Goto("GuessFarmer")
            .Else().Unhandled()

            .Do("AskEatsHay", QuestionRequest.NewDefinition()
                .SetValue(req => req.Question, "Does it eat hay")
                .SetValue(req => req.Answers, new[] { "[Y]es", "[N]o" })
                .BindOutput(res => res.Answer, "EatsHay"))

            .Check("EatsHay", "Eats hay?", FlowValueDecision <string> .NewDefinition()
                   .BindInput(req => req.SwitchValue, "EatsHay"))
            .When("Y").Goto("GuessHorse")
            .When("N").Goto("GuessCat")
            .Else().Unhandled()

            .Do("AskHasScales", QuestionRequest.NewDefinition()
                .SetValue(req => req.Question, "Does it have scales")
                .SetValue(req => req.Answers, new[] { "[Y]es", "[N]o" })
                .BindOutput(res => res.Answer, "HasScales"))

            .Check("HasScales", "Has scales?", FlowValueDecision <string> .NewDefinition()
                   .BindInput(req => req.SwitchValue, "HasScales"))
            .When("Y").Goto("GuessSnake")
            .When("N").Goto("GuessWorm")
            .Else().Unhandled()

            .Do("GuessDuck", GuessRequest.NewDefinition()
                .SetValue(req => req.Guess, "Duck"))
            .End()

            .Do("GuessFarmer", GuessRequest.NewDefinition()
                .SetValue(req => req.Guess, "Farmer"))
            .End()

            .Do("GuessHorse", GuessRequest.NewDefinition()
                .SetValue(req => req.Guess, "Horse"))
            .End()

            .Do("GuessCat", GuessRequest.NewDefinition()
                .SetValue(req => req.Guess, "Cat"))
            .End()

            .Do("GuessSnake", GuessRequest.NewDefinition()
                .SetValue(req => req.Guess, "Snake"))
            .End()

            .Do("GuessWorm", GuessRequest.NewDefinition()
                .SetValue(req => req.Guess, "Worm"))
            .End();
        }
コード例 #12
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();
        }