예제 #1
0
        //  Add two strings
        public void AddTwoStrings()
        {
            Expression <Func <ActivityContext, string> > expression =
                (env) => DummyHelper.StaticStringField1 + DummyHelper.StaticStringField2 + DummyHelper.StaticStringField3;

            Activity <string> expectedActivity = new InvokeMethod <string>()
            {
                MethodName = "Concat",
                TargetType = typeof(string),
                Parameters =
                {
                    new InArgument <string>()
                    {
                        EvaluationOrder = 0,
                        Expression      = new InvokeMethod <string>()
                        {
                            MethodName = "Concat",
                            TargetType = typeof(string),
                            Parameters =
                            {
                                new InArgument <string>()
                                {
                                    EvaluationOrder = 0,
                                    Expression      = new FieldValue <DummyHelper, string>()
                                    {
                                        FieldName = "StaticStringField1"
                                    },
                                },
                                new InArgument <string>()
                                {
                                    EvaluationOrder = 1,
                                    Expression      = new FieldValue <DummyHelper, string>()
                                    {
                                        FieldName = "StaticStringField2"
                                    },
                                }
                            }
                        },
                    },
                    new InArgument <string>()
                    {
                        EvaluationOrder = 1,
                        Expression      = new FieldValue <DummyHelper, string>()
                        {
                            FieldName = "StaticStringField3"
                        },
                    }
                }
            };

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(string),
                ExpectedNode   = expectedActivity,
                ExpressionTree = expression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <string>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #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);
            }
        }
예제 #3
0
        //  Not operator with overloading
        public void NotOperatorWithOverloading()
        {
            Expression <Func <ActivityContext, DummyHelper> > expression = (env) => !DummyHelper.Instance;
            Activity <DummyHelper> expectedActivity = new InvokeMethod <DummyHelper>()
            {
                MethodName = "op_LogicalNot",
                TargetType = typeof(DummyHelper),
                Parameters =
                {
                    new InArgument <DummyHelper>(
                        new FieldValue <DummyHelper, DummyHelper>()
                    {
                        FieldName = "Instance"
                    })
                }
            };

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(DummyHelper),
                ExpectedNode   = expectedActivity,
                ExpressionTree = expression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <DummyHelper>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null, typeof(DummyHelper));
        }
예제 #4
0
        //  Method call with argument
        public void MethodCallWithArgument()
        {
            NodeExpressionPair node = ExpressionLeafs.MethodCallNoParam;

            string         methodName = "MethodCallWithArgument";
            TestExpression expr       = new TestExpression()
            {
                ResultType   = typeof(int),
                ExpectedNode = new InvokeMethod <int>()
                {
                    MethodName = methodName,
                    TargetType = typeof(DummyHelper),
                    Parameters =
                    {
                        new InArgument <int>(
                            (InvokeMethod <int>)node.GetLeafNode())
                        {
                            EvaluationOrder = 1
                        }
                    }
                },
                ExpressionTree = Expression.Call(
                    typeof(DummyHelper).GetMethod(methodName, BindingFlags.Public | BindingFlags.Static),
                    node.LeafExpression)
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #5
0
        //  None generic variable get
        public void NoneGenericVariableGet()
        {
            Variable <int> var = new Variable <int>()
            {
                Name = "NoneGenericVariable"
            };

            Activity <int> expectedActivity = new Cast <object, int>()
            {
                Operand = var,
                Checked = false
            };

            Expression <Func <ActivityContext, int> > lambda = (env) => (int)DummyHelper.NoneGenericVariable.Get(env);

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(int),
                ExpectedNode   = expectedActivity,
                ExpressionTree = lambda
            };

            List <Variable> varsActual = new List <Variable>()
            {
                DummyHelper.NoneGenericVariable
            };

            List <Variable> varsExpected = new List <Variable>()
            {
                var
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, varsExpected, varsActual);
        }
예제 #6
0
        //  Call generic method
        public void GenericMethodCall()
        {
            NodeExpressionPair node       = ExpressionLeafs.ConstStringValue;
            string             methodName = "GenericMethod";

            MethodInfo genericMethodHanlder            = typeof(DummyHelper).GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
            MethodInfo specializedGenericMethodHandler = genericMethodHanlder.MakeGenericMethod(typeof(string));

            TestExpression expr = new TestExpression()
            {
                ResultType   = typeof(string),
                ExpectedNode = new InvokeMethod <string>()
                {
                    MethodName           = methodName,
                    TargetType           = typeof(DummyHelper),
                    GenericTypeArguments =
                    {
                        typeof(string)
                    },
                    Parameters =
                    {
                        new InArgument <string>()
                        {
                            Expression      = (Activity <string>)node.GetLeafNode(),
                            EvaluationOrder = 1
                        }
                    }
                },
                ExpressionTree = Expression.Call(
                    specializedGenericMethodHandler, node.LeafExpression)
            };

            ExpressionTestRuntime.ValidateExpressionXaml <string>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #7
0
        public void NewWithArgument()
        {
            TestExpression expr = new TestExpression()
            {
                ResultType   = typeof(String),
                ExpectedNode = new New <String>()
                {
                    Arguments =
                    {
                        new InArgument <char>('a')
                        {
                            EvaluationOrder = 0
                        },
                        new InArgument <int>(1)
                        {
                            EvaluationOrder = 1,
                        },
                    }
                },
                ExpressionTree = Expression.New(
                    typeof(String).GetConstructor(new Type[] { typeof(char), typeof(int) }),
                    Expression.Constant('a'),
                    Expression.Constant(1))
            };

            ExpressionTestRuntime.ValidateExpressionXaml <String>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #8
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);
            }
        }
예제 #9
0
        //  Indexer
        public void RValueIndexer()
        {
            Expression <Func <ActivityContext, string> > lambda = (env) => DummyHelper.StaticDictionary[1];

            Activity <string> expectedActivity = new InvokeMethod <string>()
            {
                MethodName = "get_Item",
                Parameters =
                {
                    new InArgument <int>(1)
                    {
                        EvaluationOrder = 1
                    }
                },
                TargetObject = new InArgument <Dictionary <int, string> >()
                {
                    EvaluationOrder = 0,
                    Expression      = new FieldValue <DummyHelper, Dictionary <int, string> >()
                    {
                        FieldName = "StaticDictionary"
                    }
                }
            };

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(string),
                ExpectedNode   = expectedActivity,
                ExpressionTree = lambda
            };

            ExpressionTestRuntime.ValidateExpressionXaml <string>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #10
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);
                }
            }
        }
예제 #11
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);
            }
        }
예제 #12
0
        //  Method call with ref argument
        public void MethodCallWithRefArgument()
        {
            Expression <Func <ActivityContext, int> > expression = (env) => DummyHelper.MethodCallWithRefArgument(ref DummyHelper.StaticIntField);

            string         methodName = "MethodCallWithRefArgument";
            TestExpression expr       = new TestExpression()
            {
                ResultType   = typeof(int),
                ExpectedNode = new InvokeMethod <int>()
                {
                    MethodName = methodName,
                    TargetType = typeof(DummyHelper),
                    Parameters =
                    {
                        new InOutArgument <int>()
                        {
                            Expression = new FieldReference <DummyHelper, int>
                            {
                                FieldName = "StaticIntField"
                            },
                            EvaluationOrder = 1
                        }
                    }
                },
                ExpressionTree = expression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #13
0
        public void NewWithoutArgument()
        {
            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(int),
                ExpectedNode   = new New <int>(),
                ExpressionTree = Expression.New(typeof(int))
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #14
0
        //  Static property
        public void StaticProperty()
        {
            NodeExpressionPair node = ExpressionLeafs.StaticIntProperty;
            TestExpression     expr = new TestExpression()
            {
                ResultType     = typeof(int),
                ExpectedNode   = node.GetLeafNode(),
                ExpressionTree = node.LeafExpression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #15
0
        //  Constant value
        public void ConstantValue()
        {
            NodeExpressionPair node = ExpressionLeafs.ConstIntValue;
            TestExpression     expr = new TestExpression()
            {
                ResultType     = typeof(int),
                ExpectedNode   = node.GetLeafNode(),
                ExpressionTree = node.LeafExpression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #16
0
        //  Add with generic type as operands
        public void AddGenericTypes()
        {
            Add <Nullable <int>, Nullable <int>, Nullable <int> > expectedActivity = new Add <Nullable <int>, Nullable <int>, Nullable <int> >()
            {
                Left = new InArgument <int?>()
                {
                    EvaluationOrder = 0,
                    Expression      = new New <Nullable <int> >()
                    {
                        Arguments =
                        {
                            new InArgument <int>(10)
                            {
                                EvaluationOrder = 0
                            }
                        }
                    },
                },
                Right = new InArgument <int?>()
                {
                    EvaluationOrder = 1,
                    Expression      = new New <Nullable <int> >()
                    {
                        Arguments =
                        {
                            new InArgument <int>(20)
                            {
                                EvaluationOrder = 0
                            }
                        }
                    }
                },
                Checked = false
            };

            ConstructorInfo ctorHandler = typeof(Nullable <int>).GetConstructors()[0];

            Expression expectedExpression = Expression.Add(
                Expression.New(ctorHandler, Expression.Constant(10)),
                Expression.New(ctorHandler, Expression.Constant(20)));

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(Nullable <int>),
                ExpectedNode   = expectedActivity,
                ExpressionTree = expectedExpression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <Nullable <int> >(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #17
0
        //  Method call without argument
        public void MethodCallWithoutArgument()
        {
            NodeExpressionPair node = ExpressionLeafs.MethodCallNoParam;

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(int),
                ExpectedNode   = node.GetLeafNode(),
                ExpressionTree = node.LeafExpression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #18
0
        //  Add different types that has operator overloading
        public void AddDifferentTypes()
        {
            Expression <Func <ActivityContext, DateTime> > expression =
                (env) => DummyHelper.StaticDate + DummyHelper.StaticTimeSpan;

            Activity <DateTime> expectedActivity = new InvokeMethod <DateTime>()
            {
                MethodName = "op_Addition",
                TargetType = typeof(DateTime),
                Parameters =
                {
                    new InArgument <DateTime>()
                    {
                        EvaluationOrder = 0,
                        Expression      = new FieldValue <DummyHelper, DateTime>()
                        {
                            FieldName = "StaticDate",
                        }
                    },
                    new InArgument <TimeSpan>()
                    {
                        EvaluationOrder = 1,
                        Expression      = new FieldValue <DummyHelper, TimeSpan>()
                        {
                            FieldName = "StaticTimeSpan",
                        }
                    },
                }
            };

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(DateTime),
                ExpectedNode   = expectedActivity,
                ExpressionTree = expression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <DateTime>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #19
0
        public void NewArray()
        {
            TestExpression expr = new TestExpression()
            {
                ResultType   = typeof(int[]),
                ExpectedNode = new NewArray <int[]>()
                {
                    Bounds =
                    {
                        new InArgument <int>(10)
                        {
                            EvaluationOrder = 0
                        }
                    }
                },
                ExpressionTree = Expression.NewArrayBounds(
                    typeof(int), Expression.Constant(10))
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int[]>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #20
0
        //  Static delegate call
        public void StaticDelegateCall()
        {
            NodeExpressionPair node = ExpressionLeafs.MethodCallNoParam;

            string         delegateName = "StaticDelegate";
            TestExpression expr         = new TestExpression()
            {
                ResultType   = typeof(int),
                ExpectedNode = new InvokeMethod <int>()
                {
                    MethodName = "Invoke",
                    Parameters =
                    {
                        new InArgument <int>()
                        {
                            Expression      = (Activity <int>)node.GetLeafNode(),
                            EvaluationOrder = 1,
                        }
                    },
                    TargetObject = new InArgument <Func <int, int> >()
                    {
                        Expression = new FieldValue <DummyHelper, Func <int, int> >()
                        {
                            FieldName = delegateName,
                            Operand   = null,
                        },
                        EvaluationOrder = 0
                    }
                },
                ExpressionTree = Expression.Invoke(
                    Expression.Field(
                        null, typeof(DummyHelper).GetField(delegateName, BindingFlags.Public | BindingFlags.Static)),
                    node.LeafExpression)
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #21
0
        //  Convert cast expression
        public void ConvertCast()
        {
            NodeExpressionPair node = ExpressionLeafs.StaticIntField;

            Expression linq = Expression.Convert(node.LeafExpression, typeof(double));

            Activity <double> expectedActivity = new Cast <int, double>()
            {
                Checked = false,
                Operand = new InArgument <int>(
                    (Activity <int>)node.GetLeafNode())
            };

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(double),
                ExpectedNode   = expectedActivity,
                ExpressionTree = linq
            };

            ExpressionTestRuntime.ValidateExpressionXaml <double>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }
예제 #22
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);
                    }
                }
            }
        }
예제 #23
0
        //  Method call with different expressions as argument
        public void MethodCallWithVariousParameters()
        {
            Activity <int> expectedActivity = new InvokeMethod <int>()
            {
                MethodName = "MethodCallWithVariousArgs",
                TargetType = typeof(DummyHelper),
                Parameters =
                {
                    new InArgument <int>(-1)
                    {
                        EvaluationOrder = 1
                    },
                    new InArgument <string>("hello")
                    {
                        EvaluationOrder = 2,
                    },
                    new InOutArgument <int>()
                    {
                        EvaluationOrder = 3,
                        Expression      = new FieldReference <DummyHelper, int>()
                        {
                            FieldName = "StaticIntField"
                        },
                    },
                    new InArgument <Variable <int?> >()
                    {
                        EvaluationOrder = 4,
                        Expression      = new FieldValue <DummyHelper, Variable <int?> >()
                        {
                            FieldName = "StaticNullableIntVar"
                        }
                    },
                    new InArgument <Func <int, int> >()
                    {
                        EvaluationOrder = 5,
                        Expression      = new FieldValue <DummyHelper, Func <int, int> >()
                        {
                            FieldName = "StaticDelegate"
                        }
                    },
                    new InArgument <DummyHelper>()
                    {
                        EvaluationOrder = 6,
                        Expression      = new New <DummyHelper>()
                    }
                },
            };

            Expression <Func <ActivityContext, int> > expectedExpression =
                (env) => DummyHelper.MethodCallWithVariousArgs(-1, "hello", ref DummyHelper.StaticIntField, DummyHelper.StaticNullableIntVar, DummyHelper.StaticDelegate, new DummyHelper());

            TestExpression expr = new TestExpression()
            {
                ResultType     = typeof(int),
                ExpectedNode   = expectedActivity,
                ExpressionTree = expectedExpression
            };

            ExpressionTestRuntime.ValidateExpressionXaml <int>(expr);
            ExpressionTestRuntime.ValidateExecutionResult(expr, null);
        }