Exemplo n.º 1
0
        public void InferredEvaluatorAddedOnlyOnce()
        {
            WorkDefine.Workflow testWF = new WorkDefine.Workflow("test")
            {
                Activities = new List <WorkDefine.Activity>()
                {
                    new WorkDefine.Activity()
                    {
                        //Action = "action.test",
                        Id        = "activity.test",
                        Reactions = new List <WorkDefine.Reaction>()
                        {
                            new WorkDefine.Reaction()
                            {
                                Logic = "evaluator.test", Work = "action.reaction"
                            },
                            new WorkDefine.Reaction()
                            {
                                Logic = "evaluator.test", Work = "action.reaction"
                            }
                        }
                    }
                }
            };
            StepTracer <LintTrace> tracer = new StepTracer <LintTrace>();

            tracer.TraceFirst(new LintTrace(LintStatusOptions.Sanitizing, "Testing Sanitizer"));
            Sanitizer toTest = new Sanitizer(tracer, this.defaultConfig);

            WorkDefine.Workflow sanitized = toTest.Sanitize(testWF);
            Assert.Equal(1, sanitized.Evaluators.Count(g => g.Id == "evaluator.test"));
        }
Exemplo n.º 2
0
        public void InferredNegatedEquationAddedOnlyOnce()
        {
            WorkDefine.Workflow testWF = new WorkDefine.Workflow("test")
            {
                Equations = new List <LogicDefine.Equation>()
                {
                    new LogicDefine.Equation()
                    {
                        Condition = Mchnry.Flow.Logic.Operand.And, First = "evaluator.first", Id = "equation.testeq"
                    }
                },
                Activities = new List <WorkDefine.Activity>()
                {
                    new WorkDefine.Activity()
                    {
                        //Action = "action.test",
                        Id        = "activity.test",
                        Reactions = new List <WorkDefine.Reaction>()
                        {
                            new WorkDefine.Reaction()
                            {
                                Logic = "evaluator.test", Work = "action.reaction"
                            },
                            new WorkDefine.Reaction()
                            {
                                Logic = "!equation.testeq", Work = "action.badreaction"
                            },
                            new WorkDefine.Reaction()
                            {
                                Logic = "!equation.testeq", Work = "action.anotherbadreaction"
                            }
                        }
                    }
                }
            };
            StepTracer <LintTrace> tracer = new StepTracer <LintTrace>();

            tracer.TraceFirst(new LintTrace(LintStatusOptions.Sanitizing, "Testing Sanitizer"));
            Sanitizer toTest = new Sanitizer(tracer, this.defaultConfig);

            WorkDefine.Workflow sanitized = toTest.Sanitize(testWF);
            Assert.Equal(1, sanitized.Equations.Count(g => g.Id == "equation.NOT.testeq"));
        }
Exemplo n.º 3
0
        private IRule <TModel> LoadLogic(string equationId)
        {
            StepTracer <LintTrace>    trace = new StepTracer <LintTrace>();
            StepTraceNode <LintTrace> root  = trace.TraceFirst(new LintTrace(LintStatusOptions.Loading, "Loading Logic", equationId));


            //Lint.... make sure we have everything we need first.
            Func <LogicDefine.Rule, StepTraceNode <LintTrace>, bool, IRule <TModel> > LoadRule = null;

            LoadRule = (rule, parentStep, inner) =>
            {
                StepTraceNode <LintTrace> step     = trace.TraceNext(parentStep, new LintTrace(LintStatusOptions.Inspecting, "Inspecting Rule", rule.Id));
                IRule <TModel>            toReturn = null;
                //if id is an equation, we are creating an expression

                //since we've formalized convention, we can just check that
                if (ConventionHelper.MatchesConvention(NamePrefixOptions.Equation, rule.Id, this.Configuration.Convention))
                {
                    LogicDefine.Equation eq = this.WorkflowManager.GetEquation(rule.Id);

                    IRule <TModel> first  = LoadRule(eq.First, step, true);
                    IRule <TModel> second = LoadRule(eq.Second, step, true);
                    toReturn = new Expression <TModel>(rule, eq.Condition, first, second, this, inner);
                }
                else
                {
                    LogicDefine.Evaluator ev = this.WorkflowManager.GetEvaluator(rule.Id);
                    toReturn = new Rule <TModel>(rule, this, inner);
                }



                return(toReturn);
            };



            LogicDefine.Rule eqRule = equationId;
            IRule <TModel>   loaded = LoadRule(eqRule, root, false);

            return(loaded);
        }