Ejemplo n.º 1
0
        public void FailedFunction()
        {
            using (TestHostContext hc = CreateTestContext())
            {
                // Arrange.
                var variableSets = new[]
                {
                    new { JobStatus = (TaskResult?)TaskResult.Failed, Expected = true },
                    new { JobStatus = (TaskResult?)null, Expected = false },
                    new { JobStatus = (TaskResult?)TaskResult.Canceled, Expected = false },
                    new { JobStatus = (TaskResult?)TaskResult.Succeeded, Expected = false },
                    new { JobStatus = (TaskResult?)TaskResult.SucceededWithIssues, Expected = false },
                };
                foreach (var variableSet in variableSets)
                {
                    InitializeExecutionContext(hc);
                    _ec.Object.Variables.Agent_JobStatus = variableSet.JobStatus;
                    Expressions.INode condition = _expressionManager.Parse(_ec.Object, "failed()");

                    // Act.
                    bool actual = _expressionManager.Evaluate(_ec.Object, condition);

                    // Assert.
                    Assert.Equal(variableSet.Expected, actual);
                }
            }
        }
Ejemplo n.º 2
0
        public void VariablesNamedValue()
        {
            using (TestHostContext hc = CreateTestContext())
            {
                // Arrange.
                var variableSets = new[]
                {
                    new { Condition = "eq(variables.someVARIABLE, 'someVALUE')", VariableName = "SOMEvariable", VariableValue = "SOMEvalue", Expected = true },
                    new { Condition = "eq(variables['some.VARIABLE'], 'someVALUE')", VariableName = "SOME.variable", VariableValue = "SOMEvalue", Expected = true },
                    new { Condition = "eq(variables.nosuch, '')", VariableName = "SomeVariable", VariableValue = "SomeValue", Expected = true },
                    new { Condition = "eq(variables['some.VARIABLE'], 'other value')", VariableName = "SOME.variable", VariableValue = "SOMEvalue", Expected = false },
                    new { Condition = "eq(variables.nosuch, 'SomeValue')", VariableName = "SomeVariable", VariableValue = "SomeValue", Expected = false },
                };
                foreach (var variableSet in variableSets)
                {
                    InitializeExecutionContext(hc);
                    _ec.Object.Variables.Set(variableSet.VariableName, variableSet.VariableValue);
                    Expressions.INode condition = _expressionManager.Parse(_ec.Object, variableSet.Condition);

                    // Act.
                    bool actual = _expressionManager.Evaluate(_ec.Object, condition);

                    // Assert.
                    Assert.Equal(variableSet.Expected, actual);
                }
            }
        }
Ejemplo n.º 3
0
        public bool Evaluate(IExecutionContext executionContext, Expressions.INode tree, bool hostTracingOnly = false)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));
            ArgUtil.NotNull(tree, nameof(tree));
            var expressionTrace = new TraceWriter(Trace, hostTracingOnly ? null : executionContext);

            return(tree.EvaluateBoolean(trace: expressionTrace, state: executionContext));
        }
Ejemplo n.º 4
0
        public bool Evaluate(IExecutionContext executionContext, string condition)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            // Parse the condition.
            var expressionTrace = new TraceWriter(executionContext);
            var parser          = new DT.Parser();
            var extensions      = new DT.IFunctionInfo[]
            {
                new DT.FunctionInfo <AlwaysNode>(name: Constants.Expressions.Always, minParameters: 0, maxParameters: 0),
                new DT.FunctionInfo <SucceededNode>(name: Constants.Expressions.Succeeded, minParameters: 0, maxParameters: 0),
                new DT.FunctionInfo <SucceededOrFailedNode>(name: Constants.Expressions.SucceededOrFailed, minParameters: 0, maxParameters: 0),
                new DT.FunctionInfo <VariablesNode>(name: Constants.Expressions.Variables, minParameters: 1, maxParameters: 1),
            };

            DT.INode tree = parser.CreateTree(condition, expressionTrace, extensions) ?? new SucceededNode();

            // Evaluate the tree.
            return(tree.EvaluateBoolean(trace: expressionTrace, state: executionContext));
        }