Ejemplo n.º 1
0
        private static TableDecision DummyTable(TableDecision t, Variable.Ref variableRef)
        {
            var tableDecision = t.WithInput(variableRef, out _).WithOutput(variableRef, out _)
                                .WithRule("r", r => r.Always().SkipOutput());

            return(tableDecision);
        }
Ejemplo n.º 2
0
        public void TableInputOutputErr()
        {
            // ReSharper disable once JoinDeclarationAndInitializer
            Action        act;
            TableDecision tableDecision = null;
            // ReSharper disable once NotAccessedVariable
            object o;

            // ReSharper disable once UnusedVariable
            var defDummy = new DmnDefinitionBuilder()
                           .WithInput <string>("Input", out _)
                           .WithVariable <string>("Variable", out var defDummyVariableRef)
                           .WithExpressionDecision("Decision", "Input", defDummyVariableRef, out _);

            var def = new DmnDefinitionBuilder()
                      .WithInput <string>("Input")
                      .WithVariable <string>("Variable", out var variableRef)
                      .WithTableDecision("Table", t => DummyTable(t, variableRef, out tableDecision));
            var input  = tableDecision.Inputs[0];
            var output = tableDecision.Outputs[0];

            act = () => o = input.Result;
            act.Should().Throw <DmnBuilderException>().WithMessage("* is not built yet");
            act = () => o = output.Result;
            act.Should().Throw <DmnBuilderException>().WithMessage("* is not built yet");

            act = () => input.WithVariable(null);
            act.Should().Throw <ArgumentNullException>();
            act = () => input.WithVariable(defDummyVariableRef);
            act.Should().Throw <DmnBuilderException>().WithMessage("Can't get the variable from reference*");
            act = () => input.WithExpression(null);
            act.Should().Throw <ArgumentNullException>();
            act = () => input.WithExpression(" ");
            act.Should().Throw <ArgumentException>().WithMessage("Missing expression*");

            act = () => output.WithVariable(null);
            act.Should().Throw <ArgumentNullException>();
            act = () => output.WithVariable(defDummyVariableRef);
            act.Should().Throw <DmnBuilderException>().WithMessage("Can't get the variable from reference*");

            def.Build();

            act = () => input.WithVariable(variableRef);
            act.Should().Throw <DmnBuilderException>().WithMessage("Table input is already built");
            act = () => input.WithExpression("Input");
            act.Should().Throw <DmnBuilderException>().WithMessage("Table input is already built");
            act = () => input.WithAllowedValues(new[] { "q", "s" });
            act.Should().Throw <DmnBuilderException>().WithMessage("Table input is already built");
            act = () => input.WithoutAllowedValuesConstraint();
            act.Should().Throw <DmnBuilderException>().WithMessage("Table input is already built");

            act = () => output.WithVariable(variableRef);
            act.Should().Throw <DmnBuilderException>().WithMessage("Table output is already built");
            act = () => output.WithAllowedValues(new[] { "q", "s" });
            act.Should().Throw <DmnBuilderException>().WithMessage("Table output is already built");
            act = () => output.WithoutAllowedValuesConstraint();
            act.Should().Throw <DmnBuilderException>().WithMessage("Table output is already built");
        }
Ejemplo n.º 3
0
 private static TableDecision DummyTable(TableDecision t, Variable.Ref variableRef, out TableDecision tableDecision)
 {
     tableDecision = DummyTable(t, variableRef);
     return(tableDecision);
 }
Ejemplo n.º 4
0
        public void TableRuleErr()
        {
            // ReSharper disable once JoinDeclarationAndInitializer
            Action        act;
            TableDecision tableDecision = null;
            // ReSharper disable once NotAccessedVariable
            object o;

            TableRule.TableRuleInputBuilder     ruleInputBuilder     = null;
            TableRule.TableRuleThenOrAndBuilder ruleThenOrAndBuilder = null;
            TableRule.TableRuleThenOnlyBuilder  ruleThenOnlyBuilder  = null;
            // ReSharper disable once NotAccessedVariable
            TableRule.TableRuleOutputBuilder    ruleOutputBuilder    = null;
            TableRule.TableRuleAndOutputBuilder ruleAndOutputBuilder = null;

            TableInput.Ref  tableInputRef       = null;
            TableOutput.Ref tableOutputRef      = null;
            TableInput.Ref  dummyTableInputRef  = null;
            TableOutput.Ref dummyTableOutputRef = null;

            TableRule.TableRuleOutputBuilder BuilderDelegate(TableRule.TableRuleInputBuilder builderArg)
            {
                ruleInputBuilder     = builderArg;
                ruleThenOnlyBuilder  = builderArg.Always();
                ruleThenOrAndBuilder = builderArg.When(tableInputRef, "");

                ruleOutputBuilder    = ruleThenOrAndBuilder?.SkipOutput();
                ruleAndOutputBuilder = ruleThenOrAndBuilder?.Then(tableOutputRef, "");

                return(ruleAndOutputBuilder);
            }

            // ReSharper disable once UnusedVariable
            var defDummy = new DmnDefinitionBuilder()
                           .WithInput <string>("Input")
                           .WithVariable <string>("Variable", out var dummyVariableRef)
                           .WithTableDecision("Table", t =>
            {
                tableDecision = t;
                t
                .WithInput(dummyVariableRef, out dummyTableInputRef)
                .WithOutput(dummyVariableRef, out dummyTableOutputRef)
                .WithRule("r", r => r.Always().SkipOutput());
                return(t);
            });

            var def = new DmnDefinitionBuilder()
                      .WithInput <string>("Input")
                      .WithVariable <string>("Variable", out var variableRef)
                      .WithTableDecision("Table", t =>
            {
                tableDecision = t;
                t
                .WithInput(variableRef, out tableInputRef)
                .WithOutput(variableRef, out tableOutputRef)
                .WithRule("r", BuilderDelegate);
                return(t);
            });

            var rule = tableDecision.Rules[0];

            act = () => o = rule.Result;
            act.Should().Throw <DmnBuilderException>().WithMessage("* is not built yet");

            act = () => ruleInputBuilder?.When(null, "input");
            act.Should().Throw <ArgumentNullException>();
            act = () => ruleInputBuilder?.When(dummyTableInputRef, "input");
            act.Should().Throw <DmnBuilderException>().WithMessage("Input reference is not valid for current table");

            act = () => ruleThenOrAndBuilder?.And(null, "input");
            act.Should().Throw <ArgumentNullException>();
            act = () => ruleThenOrAndBuilder?.And(dummyTableInputRef, "input");
            act.Should().Throw <DmnBuilderException>().WithMessage("Input reference is not valid for current table");
            act = () => ruleThenOrAndBuilder?.Then(null, "output");
            act.Should().Throw <ArgumentNullException>();
            act = () => ruleThenOrAndBuilder?.Then(dummyTableOutputRef, "output");
            act.Should().Throw <DmnBuilderException>().WithMessage("Output reference is not valid for current table");

            act = () => ruleThenOnlyBuilder?.Then(null, "output");
            act.Should().Throw <ArgumentNullException>();
            act = () => ruleThenOnlyBuilder?.Then(dummyTableOutputRef, "output");
            act.Should().Throw <DmnBuilderException>().WithMessage("Output reference is not valid for current table");

            act = () => ruleAndOutputBuilder?.And(null, "output");
            act.Should().Throw <ArgumentNullException>();
            act = () => ruleAndOutputBuilder?.And(dummyTableOutputRef, "output");
            act.Should().Throw <DmnBuilderException>().WithMessage("Output reference is not valid for current table");

            def.Build();

            act = () => o = ruleInputBuilder?.Always();
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");
            act = () => o = ruleInputBuilder?.When(tableInputRef, "");
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");

            act = () => o = ruleThenOrAndBuilder?.SkipOutput();
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");
            act = () => o = ruleThenOrAndBuilder?.Then(tableOutputRef, "");
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");
            act = () => o = ruleThenOrAndBuilder?.And(tableInputRef, "");
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");

            act = () => o = ruleThenOnlyBuilder?.SkipOutput();
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");
            act = () => o = ruleThenOnlyBuilder?.Then(tableOutputRef, "");
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");

            act = () => o = ruleAndOutputBuilder?.And(tableOutputRef, "");
            act.Should().Throw <DmnBuilderException>().WithMessage("Table rule is already built");
        }
Ejemplo n.º 5
0
        public void TableDecisionErr()
        {
            // ReSharper disable once JoinDeclarationAndInitializer
            Action        act;
            TableDecision tableDecision = null;

            // ReSharper disable once UnusedVariable
            var defDummy = new DmnDefinitionBuilder()
                           .WithInput <string>("Input", out _)
                           .WithVariable <string>("Variable", out var defDummyVariableRef)
                           .WithExpressionDecision("Decision", "Input", defDummyVariableRef, out _);

            var def = new DmnDefinitionBuilder()
                      .WithInput <string>("Input")
                      .WithVariable <string>("Variable", out var variableRef)
                      .WithTableDecision("Table", t => DummyTable(t, variableRef, out tableDecision));

            act = () => tableDecision.WithInput((Variable.Ref)null, out _);
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithInput((Variable.Ref)null, out _, "a", "b");
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithInput((string)null, out _);
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithInput((string)null, out _, "a", "b");
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithInput(" ", out _);
            act.Should().Throw <ArgumentException>().WithMessage("Missing expression*");
            act = () => tableDecision.WithInput(" ", out _, "a", "b");
            act.Should().Throw <ArgumentException>().WithMessage("Missing expression*");
            act = () => tableDecision.WithInput(defDummyVariableRef, out _);
            act.Should().Throw <DmnBuilderException>().WithMessage("Can't get the variable from reference*");
            act = () => tableDecision.WithInput(defDummyVariableRef, out _, "a", "b");
            act.Should().Throw <DmnBuilderException>().WithMessage("Can't get the variable from reference*");

            act = () => tableDecision.WithOutput(null, out _);
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithOutput(null, out _, "a", "b");
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithOutput(defDummyVariableRef, out _);
            act.Should().Throw <DmnBuilderException>().WithMessage("Can't get the variable from reference*");
            act = () => tableDecision.WithOutput(defDummyVariableRef, out _, "a", "b");
            act.Should().Throw <DmnBuilderException>().WithMessage("Can't get the variable from reference*");

            act = () => tableDecision.WithRule(null, r => r.Always().SkipOutput());
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithRule(null, "desc", r => r.Always().SkipOutput());
            act.Should().Throw <ArgumentNullException>();
            act = () => tableDecision.WithRule(" ", r => r.Always().SkipOutput());
            act.Should().Throw <ArgumentException>().WithMessage("Missing rule name*");
            act = () => tableDecision.WithRule(" ", "desc", r => r.Always().SkipOutput());
            act.Should().Throw <ArgumentException>().WithMessage("Missing rule name*");
            act = () => tableDecision.WithRule("r", r => r.Always().SkipOutput());
            act.Should().Throw <DmnBuilderException>().WithMessage("Rule * already exists");
            act = () => tableDecision.WithRule("r", "desc", r => r.Always().SkipOutput());
            act.Should().Throw <DmnBuilderException>().WithMessage("Rule * already exists");

            def.Build();

            act = () => tableDecision.WithInput(variableRef, out _);
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");
            act = () => tableDecision.WithInput(variableRef, out _, "a", "b");
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");
            act = () => tableDecision.WithInput("Input", out _);
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");
            act = () => tableDecision.WithInput("Input", out _, "a", "b");
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");

            act = () => tableDecision.WithOutput(variableRef, out _);
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");
            act = () => tableDecision.WithOutput(variableRef, out _, "a", "b");
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");

            act = () => tableDecision.WithRule("r", r => r.Always().SkipOutput());
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");
            act = () => tableDecision.WithRule("r", "desc", r => r.Always().SkipOutput());
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");

            act = () => tableDecision.WithHitPolicy(HitPolicyEnum.Any);
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");
            act = () => tableDecision.WithAggregation(CollectHitPolicyAggregationEnum.List);
            act.Should().Throw <DmnBuilderException>().WithMessage("Decision is already built");


            var def2 = new DmnDefinitionBuilder()
                       .WithInput <string>("Input")
                       .WithVariable <string>("Variable", out var variable2Ref)
                       .WithTableDecision("Table", t => t
                                          .WithOutput(variable2Ref, out _)
                                          .WithRule("r", r => r.Always().SkipOutput()));

            act = () => def2.Build();
            act.Should().Throw <DmnBuilderException>().WithMessage("At least one input must be defined for decision table *");

            var def3 = new DmnDefinitionBuilder()
                       .WithInput <string>("Input")
                       .WithVariable <string>("Variable", out var variable3Ref)
                       .WithTableDecision("Table", t => t
                                          .WithInput(variable3Ref, out _)
                                          .WithRule("r", r => r.Always().SkipOutput()));

            act = () => def3.Build();
            act.Should().Throw <DmnBuilderException>().WithMessage("At least one output must be defined for decision table *");

            var def4 = new DmnDefinitionBuilder()
                       .WithInput <string>("Input")
                       .WithVariable <string>("Variable", out var variable4Ref)
                       .WithTableDecision("Table", t => t
                                          .WithInput(variable4Ref, out _)
                                          .WithOutput(variable4Ref, out _));

            act = () => def4.Build();
            act.Should().Throw <DmnBuilderException>().WithMessage("At least one rule must be defined for decision table *");
        }