Exemple #1
0
        public void CheckAndUpdateVariableType_NotMatch_Test()
        {
            var    v   = new DmnVariableDefinition("TEST", typeof(long));
            Action act = () => InvokeCheckAndUpdateVariableType(v, "integer");

            act.Should().Throw <DmnParserException>().WithMessage("Types for variable TEST don't match*");
        }
        public void CheckAndUpdateVariableType_EmptyType_Test()
        {
            var    v   = new DmnVariableDefinition("TEST");
            Action act = () => InvokeCheckAndUpdateVariableType(v, "");

            act.Should().NotThrow();
        }
Exemple #3
0
        /// <summary>
        /// Adds a variable to catalog
        /// </summary>
        /// <param name="variable">Variable definition builder to add</param>
        /// <returns>This variable catalog</returns>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the catalog has already been built</exception>
        public VariableCatalog AddVariable(Variable variable)
        {
            if (IsBuilt)
            {
                throw new DmnBuilderException("Variable catalog is already built");
            }
            if (variable == null)
            {
                throw new ArgumentNullException(nameof(variable));
            }
            var name = DmnVariableDefinition.NormalizeVariableName(variable.Name);

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Missing variable name", nameof(name));
            }

            VariablesInternal.Add(name, variable);
            VariablesByRef.Add(variable.Reference, variable);

            return(this);
        }
Exemple #4
0
        public void CheckAndUpdateVariableType_Match_Test()
        {
            var    v   = new DmnVariableDefinition("TEST", typeof(int));
            Action act = () => InvokeCheckAndUpdateVariableType(v, "integer");

            act.Should().NotThrow();
        }
Exemple #5
0
        /// <summary>
        /// Adds the (non-input) variable of given <paramref name="name"/> and <paramref name="variableType">type</paramref> into the definition
        /// </summary>
        /// <param name="name">Name of the variable to add</param>
        /// <param name="variableType">Type of the variable to add</param>
        /// <param name="variableRef">Reference to the variable added</param>
        /// <returns>The current <see cref="DmnDefinitionBuilder"/></returns>
        /// <exception cref="DmnBuilderException">Throws <see cref="DmnBuilderException"/> when the definition has already been built</exception>
        public DmnDefinitionBuilder WithVariable(string name, Type variableType, out Variable.Ref variableRef)
        {
            if (IsBuilt)
            {
                throw Logger.Error <DmnBuilderException>("Definition is already built");
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Missing variable name", nameof(name));
            }

            var variableName = DmnVariableDefinition.NormalizeVariableName(name);

            if (Variables.Variables.ContainsKey(variableName))
            {
                throw Logger.Error <DmnBuilderException>($"Duplicate variable name {variableName} (normalized from {name})");
            }

            var variable = new Variable(Variables, Decisions, variableName, variableType);

            variableRef = variable.Reference;
            Variables.AddVariable(variable);

            return(this);
        }
 /// <summary>
 /// CTOR
 /// </summary>
 /// <param name="index">Index of the input (order)</param>
 /// <param name="variable">Input source variable (the variable value is compared to the rules)</param>
 /// <param name="expression">Input source expression (the evaluated expression is compared to the rules)</param>
 /// <param name="allowedValues">Optional list of allowed values</param>
 public DmnDecisionTableInput(
     int index, DmnVariableDefinition variable,
     string expression = null, List <string> allowedValues = null)
 {
     Index         = index;
     Variable      = variable;
     Expression    = expression;
     AllowedValues = allowedValues;
 }
Exemple #7
0
 /// <summary>
 /// CTOR
 /// </summary>
 /// <param name="name">Unique name of the decision</param>
 /// <param name="expression">Decision expression</param>
 /// <param name="output">Decision output definition</param>
 /// <param name="requiredInputs">Decision required inputs (input variables)</param>
 /// <param name="requiredDecisions">List of decisions, the decision depends on</param>
 public DmnExpressionDecision(
     string name,
     string expression,
     DmnVariableDefinition output,
     List <DmnVariableDefinition> requiredInputs, List <IDmnDecision> requiredDecisions)
     : base(name, requiredInputs, requiredDecisions)
 {
     Expression = expression;
     Output     = output;
 }
Exemple #8
0
        /// <summary>
        /// Sets the <paramref name="name">named</paramref> input parameter <paramref name="value"/>
        /// </summary>
        /// <remarks>
        /// Variable <see cref="DmnExecutionVariable.Value"/> setter doesn't allow to set the value for the input parameters to prevent the change of them,
        ///  so <see cref="DmnExecutionVariable.SetInputParameterValue"/> is to be used explicitly
        /// </remarks>
        /// <param name="name">Name of the input parameter</param>
        /// <param name="value">Value of the input parameter</param>
        /// <returns><see cref="DmnExecutionContext"/></returns>
        /// <exception cref="ArgumentException"><paramref name="name"/> is null or empty</exception>
        /// <exception cref="DmnExecutorException">Input parameter with given <paramref name="name"/> doesn't exist</exception>
        public virtual DmnExecutionContext WithInputParameter(string name, object value)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw Logger.Fatal <ArgumentException>($"{nameof(name)} is null or empty");
            }

            name = DmnVariableDefinition.NormalizeVariableName(name);
            var variable = Variables?.Values.FirstOrDefault(i => i.IsInputParameter && i.Name == name);

            if (variable == null)
            {
                throw Logger.Fatal <DmnExecutorException>($"WithInputParameter: {name} is not an input parameter");
            }

            variable.SetInputParameterValue(value);
            Logger.Info($"Execution context input parameter {name} set to {value}");
            return(this);
        }
 private static void InvokeCheckAndUpdateVariableType(DmnVariableDefinition var, string typeStr)
 {
     TestTools.InvokeNonPublicStaticMethod <DmnDefinitionFactory>("CheckAndUpdateVariableType", var, typeStr);
 }
 /// <summary>
 /// CTOR
 /// </summary>
 /// <param name="index">Index of the output (order)</param>
 /// <param name="variable">Variable to store the output to</param>
 /// <param name="allowedValues">Optional list of allowed values</param>
 public DmnDecisionTableOutput(int index, DmnVariableDefinition variable, List <string> allowedValues = null)
 {
     Index         = index;
     Variable      = variable;
     AllowedValues = allowedValues;
 }