Ejemplo n.º 1
0
        //  Test Cast TypeAs unary expression
        public void CastTypeAsTest()
        {
            _operators = new List <UnaryOperator>()
            {
                UnaryOperator.Cast,
                UnaryOperator.CheckedCast,
                UnaryOperator.TypeAs
            };

            _leafNode = new List <NodeExpressionPair>()
            {
                ExpressionLeafs.ConstStringValue,
                ExpressionLeafs.StaticStringField,
                ExpressionLeafs.StaticStringProperty,
            };

            Variable <String> stringVar = LeafHelper.GetVariable <string>();

            stringVar.Default = "String Variable";

            List <Variable> variables = new List <Variable>()
            {
                stringVar
            };

            int numberOfTests = 0;

            foreach (TestUnaryExpression expr in EnumerateTest <String>(0, 2))
            {
                numberOfTests++;
                //Log.Info(numberOfTests.ToString());
                ExpressionTestRuntime.ValidateExpressionXaml <string>(expr);
                ExpressionTestRuntime.ValidateExecutionResult(expr, variables);
            }
        }
Ejemplo n.º 2
0
        //  Test value type unary expression
        public void ValueTypeUnaryExpressionTest()
        {
            _operators = new List <UnaryOperator>()
            {
                UnaryOperator.Not,
                UnaryOperator.Cast,
                UnaryOperator.CheckedCast
            };

            _leafNode = new List <NodeExpressionPair>()
            {
                ExpressionLeafs.ConstIntValue,
                ExpressionLeafs.StaticIntField,
                ExpressionLeafs.StaticIntProperty,
            };

            List <Variable> variables = new List <Variable>()
            {
                LeafHelper.GetVariable <int>()
            };

            int numberOfTests = 0;

            foreach (TestUnaryExpression expr in EnumerateTest <int>(0, 2))
            {
                numberOfTests++;
                //Log.Info(numberOfTests.ToString());
                ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
                ExpressionTestRuntime.ValidateExecutionResult(expr, variables);
            }
        }
Ejemplo n.º 3
0
        //  Logical operator test
        public void LogicalOperatorTest()
        {
            _operators = new List <BinaryOperator>()
            {
                BinaryOperator.And,
                BinaryOperator.OrElse,
                BinaryOperator.Or,
                BinaryOperator.AndAlso
            };

            _leafNode = new List <NodeExpressionPair>()
            {
                ExpressionLeafs.ConstBooleanTrue,
                ExpressionLeafs.ConstBooleanFalse,
                ExpressionLeafs.StaticBooleanField,
                ExpressionLeafs.StaticBooleanProperty,
            };

            List <Variable> variables = new List <Variable>()
            {
                LeafHelper.GetVariable <Boolean>()
            };

            int numberOfTests = 0;

            foreach (TestBinaryExpression binExpr in EnumerateTest <Boolean>(0, 2))
            {
                numberOfTests++;
                //Log.Info(numberOfTests.ToString());
                ExpressionTestRuntime.ValidateExpressionXaml <Boolean>(binExpr);
                ExpressionTestRuntime.ValidateExecutionResult(binExpr, variables);
            }
        }
Ejemplo n.º 4
0
        //  Bitwise operator test
        public void BitwiseOperatorTest()
        {
            _operators = new List <BinaryOperator>()
            {
                BinaryOperator.And,
                BinaryOperator.Or
            };

            _leafNode = new List <NodeExpressionPair>()
            {
                ExpressionLeafs.ConstIntValue,
                ExpressionLeafs.StaticIntField,
                ExpressionLeafs.StaticIntProperty,
                ExpressionLeafs.UnsupportedBinaryOperator
            };

            List <Variable> variables = new List <Variable>()
            {
                LeafHelper.GetVariable <int>()
            };

            int numberOfTests = 0;

            foreach (TestBinaryExpression binExpr in EnumerateTest <int>(0, 2))
            {
                numberOfTests++;
                //Log.Info(numberOfTests.ToString());

                ExpressionTestRuntime.ValidateExpressionXaml <int>(binExpr);
                if (binExpr.ExpectedConversionException == null)
                {
                    ExpressionTestRuntime.ValidateExecutionResult(binExpr, variables);
                }
            }
        }
Ejemplo n.º 5
0
        // Comments copied from ExpressionServices.cs:
        // This is to handle the leaf nodes as a variable
        //
        // Linq actually generate a temp class wrapping all the local variables.
        //
        // The real expression object look like
        // new TempClass() { A = a }.A.Get(env)
        //
        // A is a field
        //
        // This is why the logic of the code below follows.
        // This is pretty dependent on Linq implementation.

        // The test is to simulate the scenario by creating the Linq expression as:
        // (env) => TempClass().A.Get(env)
        public static Expression GetMemberAccessVariableExpression <T>()
        {
            MethodInfo  getMethodInfo = typeof(Variable <T>).GetMethod("Get", new Type[] { typeof(ActivityContext) });
            DummyHelper dummy         = new DummyHelper();

            // DummyHelper.<T>Var = LeafHelper.GetVariable<T>();
            FieldInfo fieldInfo;

            fieldInfo = typeof(DummyHelper).GetField(typeof(T).Name + "Var");
            fieldInfo.SetValue(dummy, LeafHelper.GetVariable <T>());

            return(Expression.Call(
                       Expression.Field(Expression.Constant(dummy), typeof(DummyHelper).GetField(typeof(T).Name + "Var")),
                       getMethodInfo,
                       TestExpression.EnvParameter));
        }
Ejemplo n.º 6
0
        //  Comparison operator test
        public void ComparisonOperatorTest()
        {
            _operators = new List <BinaryOperator>()
            {
                BinaryOperator.Add,
                BinaryOperator.CheckedAdd,
                BinaryOperator.Subtract,
                BinaryOperator.CheckedSubtract,
                BinaryOperator.Multiply,
                BinaryOperator.CheckedMultiply,
                BinaryOperator.Divide,
                BinaryOperator.And,
                BinaryOperator.Or
            };

            List <BinaryOperator> comparisonOperators = new List <BinaryOperator>()
            {
                BinaryOperator.Equal,
                BinaryOperator.GreaterThan,
                BinaryOperator.GreaterThanOrEqual,
                BinaryOperator.LessThan,
                BinaryOperator.LessThanOrEqual
            };

            _leafNode = new List <NodeExpressionPair>()
            {
                ExpressionLeafs.ConstIntValue,
                ExpressionLeafs.StaticIntField,
                ExpressionLeafs.StaticIntProperty,
                ExpressionLeafs.VariableInWrapper
            };

            List <Variable> variables = new List <Variable>()
            {
                LeafHelper.GetVariable <int>()
            };

            int numberOfTests = 0;

            foreach (BinaryOperator op in comparisonOperators)
            {
                TestBinaryExpression binExpr = new TestBinaryExpression()
                {
                    Operator   = op,
                    ResultType = typeof(Boolean),
                };

                foreach (TestExpression left in EnumerateTest <int>(0, 1))
                {
                    numberOfTests++;
                    //Log.Info(numberOfTests.ToString());

                    binExpr.Left = left;

                    foreach (TestExpression right in EnumerateTest <int>(0, 1))
                    {
                        binExpr.Right = right;
                    }
                    ExpressionTestRuntime.ValidateExpressionXaml <bool>(binExpr);
                    if (binExpr.ExpectedConversionException == null)
                    {
                        ExpressionTestRuntime.ValidateExecutionResult(binExpr, variables);
                    }
                }
            }
        }