Пример #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);
        }
Пример #2
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 *");
        }