public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new string[] { "A", "B", "C", "D" });
            var expr2 = xgr.FromFunc(() => new string[] { "A", "B", "C", "D" });

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test002()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new NewConstructorData(default(string)));
            var expr2 = xgr.FromFunc(() => new NewConstructorData(default(int)));

            _assert.AreNotEqual(expr1, expr2);
        }
Пример #3
0
        public virtual void Test014()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new string[] { "B", "A" });
            var expr2 = xgr.FromFunc(() => new string[] { "A", "A" });

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => default(MethodCallTestData).TwoArgMethod(default(string), default(string)));
            var expr2 = xgr.FromFunc(() => default(MethodCallTestData).TwoArgMethod(default(string), default(string)));

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => default(MemberAccessTestData).IntOne);
            var expr2 = xgr.FromFunc(() => default(MemberAccessTestData).StringOne);

            _assert.AreNotEqual(expr1, expr2);
        }
        public void Test001()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.MultiProject(
                ()=>new {
                    FieldOne = 1,
                    FieldTwo = "ABC"
                },
                x=>new InitializerOne {
                    IntField = x.FieldOne,
                    StringField = x.FieldTwo
                },
                _initializerOneTemplate,
                x=>new InitializerTwo {
                    StringFieldOne = x.FieldTwo + "DEF",
                    StringFieldTwo = "GHI" + x.FieldTwo
                },
                _initializerTwoTemplate,
                (x,y)=>new {
                    InitializerOneResult = x,
                    InitializerTwoResult = y
                }
            );

            var inputPlaceholder = xgr.FromFunc(()=>new {
                FieldOne = 1,
                FieldTwo = "ABC"
            });
            var expectations = xgr.FromFunc(inputPlaceholder, x=>new {
                InitializerOneResult = (new InitializerOne {
                        IntField = x.FieldOne,
                        StringField = x.FieldTwo
                    }).StringField + (new InitializerOne
                    {
                        IntField = x.FieldOne,
                        StringField = x.FieldTwo
                    }).IntField,
                InitializerTwoResult = (new InitializerTwo {
                        StringFieldOne = x.FieldTwo + "DEF",
                        StringFieldTwo = "GHI" + x.FieldTwo
                    }).StringFieldTwo + (new InitializerTwo
                    {
                        StringFieldOne = x.FieldTwo + "DEF",
                        StringFieldTwo = "GHI" + x.FieldTwo
                    }).StringFieldOne
            });

            var inputParam = Expression.Parameter(inputPlaceholder.ReturnType);
            var expected = Expression.Lambda(
                ExpressionReplacer.Replace(expectations.Body, inputPlaceholder.Body, inputParam),
                inputParam
            );

            var comparer = new ExpressionComparer();
            Assert.IsTrue(comparer.AreEqual(expected, e1));
        }
        public virtual void Test002()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new string[10]);
            var expr2 = xgr.FromFunc(() => new string[10]);

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test003()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => default(MethodCallTestData).IntMethodTwo());
            var expr2 = xgr.FromFunc(() => default(MethodCallTestData).IntMethodOne());

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test003()
        {
            var xgr = new ExpressionGenerator();

            var p1 = xgr.FromFunc(()=>default(string));
            var expr1 = xgr.FromFunc(p1, a => new NewConstructorData(a));
            var expr2 = xgr.FromFunc(p1, a => new NewConstructorData(a));

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test003()
        {
            var xgr = new ExpressionGenerator();

            var p1    = xgr.FromFunc(() => default(string));
            var expr1 = xgr.FromFunc(p1, a => new NewConstructorData(a));
            var expr2 = xgr.FromFunc(p1, a => new NewConstructorData(a));

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test009()
        {
            var xgr = new ExpressionGenerator();

            MemberAccessTestData constant = null;

            var expr1 = xgr.FromFunc(() => default(MemberAccessTestData).StringOne);
            var expr2 = xgr.FromFunc(() => constant.StringOne);

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test027()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new { // empty anonymous type
            });
            var expr2 = xgr.FromFunc(() => new { // empty anonymous type
            });

            _assert.AreEqual(expr1, expr2);
        }
        public void Test006()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.FromFunc(() => default(int));
            var e2 = xgr.FromFunc(() => default(string));

            var result = xgr.ConvertExpressions(e1, e2);

            Assert.AreEqual(e1.Body, result.Left);
            Assert.AreEqual(e2.Body, result.Right);
        }
        public void Test005()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.FromFunc(() => default(long?));
            var e2 = xgr.FromFunc(() => default(long?));

            var result = xgr.ConvertExpressions(e1, e2);

            Assert.AreEqual(e1.Body, result.Left);
            Assert.AreEqual(e2.Body, result.Right);
        }
        public virtual void Test011()
        {
            var xgr = new ExpressionGenerator();

            var obj1Expr = Expression.Lambda <Func <MethodCallTestData> >(Expression.Constant(null, typeof(MethodCallTestData)));
            var obj2Expr = Expression.Lambda <Func <MethodCallTestData> >(Expression.Constant(null, typeof(MethodCallTestData)));

            var expr1 = xgr.FromFunc(obj1Expr, obj1 => obj1.IntMethodOne());
            var expr2 = xgr.FromFunc(obj2Expr, obj2 => obj2.IntMethodOne());

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test022()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new {
                IntOne = default(long)
            });
            var expr2 = xgr.FromFunc(() => new {
                IntOne = default(int)
            });

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test001()
        {
            var xgr = new ExpressionGenerator();

            // this does not actually generate a ListInit expression
            var expr1 = xgr.FromFunc(()=>new Dictionary<int, int> {
            });
            var expr2 = xgr.FromFunc(() => new Dictionary<int, int> {
            });

            _assert.AreEqual(expr1, expr2);
            Assert.IsNotNull(expr1.Body as MemberInitExpression, "Expected this to be a memberInit");
        }
        public void Test004()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.FromFunc(() => default(long?));
            var e2 = xgr.FromFunc(() => default(long));

            var result = xgr.ConvertExpressions(e1, e2);

            Assert.AreEqual(e1.Body, result.Left);
            Assert.AreNotEqual(e2.Body, result.Right);
            Assert.AreEqual(typeof(long?), result.Right.Type);
        }
Пример #19
0
        public virtual void Test001()
        {
            var xgr = new ExpressionGenerator();

            // this does not actually generate a ListInit expression
            var expr1 = xgr.FromFunc(() => new Dictionary <int, int> {
            });
            var expr2 = xgr.FromFunc(() => new Dictionary <int, int> {
            });

            _assert.AreEqual(expr1, expr2);
            Assert.IsNotNull(expr1.Body as MemberInitExpression, "Expected this to be a memberInit");
        }
        public virtual void Test002()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new Dictionary<int, int>
            {
                {1, 1 }
            });
            var expr2 = xgr.FromFunc(() => new Dictionary<int, int>
            {
                {1, 1 }
            });

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test016()
        {
            var xgr = new ExpressionGenerator();

            MethodCallTestData obj1 = new MethodCallTestData();
            MethodCallTestData obj2 = new MethodCallTestData();

            var expr1 = xgr.FromFunc(() => obj1.IntMethodOne());
            var expr2 = xgr.FromFunc(() => obj2.IntMethodOne());

            // these aren't equal because the expressions (.NET 3.5 -> .nET 4.5.2+) are generated as a member access
            // on a constant over the invisible closure, instead of a constant reference to the objects themselves
            // TODO: Keep this up to date as new versions are released
            _assert.AreNotEqual(expr1, expr2);
        }
Пример #22
0
        public virtual void Test006()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new Dictionary <int, int>
            {
                { 1, 1 }
            });
            var expr2 = xgr.FromFunc(() => new Dictionary <int, int>(1)
            {
                { 1, 1 }
            });

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test018()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringOne = default(string)
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringOne = default(string)
            });

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test024()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData(0)
            {
                IntOne = default(int)
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData(1)
            {
                IntOne = default(int)
            });

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test026()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                NestedList = {}
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                NestedList = {}
            });

            _assert.AreEqual(expr1, expr2);
        }
        public void Test002()
        {
            var xgr = new ExpressionGenerator();
            var l2 = Expression.Lambda<Func<int>>(Expression.Default(typeof(int)));
            var l1 = xgr.FromFunc(l2, i2 => new MemberInitData()
            {
                FieldOne = i2
            });
            var e1 = (MemberInitExpression)l1.Body;
            var e2 = e1.NewExpression;
            var e3 = l2.Body;

            var replace = new Dictionary<Expression, Expression>
            {
                { e2, Expression.New(e2.Constructor) }
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.WasNotProduced(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == replace[e2]);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[0]).Expression == e3);
            assert.WasVisited(e2);
            assert.WasProduced(replace[e2]);
            assert.WasNotProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(e3);

            assert.TotalVisits(3);
            assert.TotalProduced(3);
        }
Пример #27
0
        public void Test003()
        {
            var xgr = new ExpressionGenerator();
            var l2  = Expression.Lambda <Func <int> >(Expression.Default(typeof(int)));
            var l1  = xgr.FromFunc(l2, i2 => new MemberInitData()
            {
                FieldOne = i2
            });
            var e1 = (MemberInitExpression)l1.Body;
            var e2 = e1.NewExpression;
            var e3 = l2.Body;

            var replace = new Dictionary <Expression, Expression>
            {
                { e3, Expression.Constant(1) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.WasNotProduced(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == e2);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[0]).Expression == replace[e3]);
            assert.WasVisited(e2);
            assert.WasProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasNotProduced(e3);

            assert.TotalVisits(3);
            assert.TotalProduced(3);
        }
        static Expression <Func <object> > LambdaToType <T>(Expression <Func <T> > expr)
        {
            var xgr      = new ExpressionGenerator();
            var message2 = xgr.FromFunc(expr, m => (object)m);

            return(message2);
        }
Пример #29
0
        public static void IsEmpty <T>(this IAssertionTool assertTool, Expression <Func <IEnumerable <T> > > collection, string msg, params object[] fmt)
        {
            var xgr  = new ExpressionGenerator();
            var eval = assertTool.GetExpressionEvaluator();
            var exp  = xgr.FromFunc(collection, c => c.Count());

            assertTool.AreEqual(0, exp, msg, fmt);
        }
        public virtual void Test005()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new {
                IntOne = default(int),
                IntTwo = default(int),
                StringOne = default(string),
                StringTwo = default(string),
            });
            var expr2 = xgr.FromFunc(() => new {
                IntOne = default(int),
                IntTwo = default(int),
                StringOne = default(string),
                StringTwo = default(string),
            });

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test005()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new {
                IntOne    = default(int),
                IntTwo    = default(int),
                StringOne = default(string),
                StringTwo = default(string),
            });
            var expr2 = xgr.FromFunc(() => new {
                IntOne    = default(int),
                IntTwo    = default(int),
                StringOne = default(string),
                StringTwo = default(string),
            });

            _assert.AreEqual(expr1, expr2);
        }
Пример #32
0
        public virtual void Test004()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new Dictionary <int, int>
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 3 },
            });
            var expr2 = xgr.FromFunc(() => new Dictionary <int, int>
            {
                { 1, 1 },
                { 2, 2 },
                { 3, 3 },
            });

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test007()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringOne = default(string),
                StringTwo = default(string),
                IntOne = default(int),
                IntTwo = default(int),
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringTwo = default(string),
                IntOne = default(int),
                IntTwo = default(int),
            });

            _assert.AreNotEqual(expr1, expr2);
        }
Пример #34
0
        public void Test004()
        {
            var xgr = new ExpressionGenerator();
            var q   = Enumerable.Range(0, 1).Select(x => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            }).AsQueryable();

            var e1 = xgr.MultiProject(
                q,
                x => x.FieldTwo + x.FieldOne,
                x => "GHI" + x.FieldTwo + x.FieldTwo + "DEF",
                (x, y) => new {
                InitializerOneResult = x,
                InitializerTwoResult = y
            }
                );

            var inputPlaceholder = xgr.FromFunc(() => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            });
            var expectations = xgr.FromFunc(inputPlaceholder, x => new {
                InitializerOneResult = x.FieldTwo + x.FieldOne,
                InitializerTwoResult = "GHI" + x.FieldTwo + x.FieldTwo + "DEF"
            });

            var inputParam = Expression.Parameter(inputPlaceholder.ReturnType);
            var expected   = Expression.Lambda(
                ExpressionReplacer.Replace(expectations.Body, inputPlaceholder.Body, inputParam),
                inputParam
                );

            var inner1 = e1.Expression as MethodCallExpression;
            var inner2 = inner1.Arguments[1] as UnaryExpression;
            var inner3 = inner2.Operand as LambdaExpression;

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, inner3));
        }
        public virtual void Test015()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringOne = default(string),
                StringTwo = default(string),
                IntOne    = default(int),
                IntTwo    = default(int),
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                StringOne = "ABC",
                StringTwo = default(string),
                IntOne    = default(int),
                IntTwo    = default(int),
            });

            _assert.AreNotEqual(expr1, expr2);
        }
        public void Test004()
        {
            var xgr = new ExpressionGenerator();
            var xpr = new ExpressionReader();

            var expr = xgr.FromFunc(() => default(IQueryable <int>).Where(x => x > 10));

            var result = xpr.GetLambda(expr);

            Assert.AreEqual(expr, result);
            Assert.IsInstanceOfType(result, typeof(LambdaExpression));
        }
        public void Test001()
        {
            var xgr = new ExpressionGenerator();
            var xpr = new ExpressionReader();

            var expr = xgr.FromFunc(()=>default(IQueryable<int>).Where(x=>x > 10));
            var expr2 = ((MethodCallExpression)expr.Body).Arguments[1];

            var body = xpr.GetLambda(expr2);

            Assert.AreNotEqual(expr2, body);
            Assert.IsInstanceOfType(body, typeof(LambdaExpression));
        }
        public void Test001()
        {
            var xgr = new ExpressionGenerator();
            var xpr = new ExpressionReader();

            var expr  = xgr.FromFunc(() => default(IQueryable <int>).Where(x => x > 10));
            var expr2 = ((MethodCallExpression)expr.Body).Arguments[1];

            var body = xpr.GetLambda(expr2);

            Assert.AreNotEqual(expr2, body);
            Assert.IsInstanceOfType(body, typeof(LambdaExpression));
        }
Пример #39
0
        public void Test023()
        {
            var xgr = new ExpressionGenerator();
            var l3  = Expression.Lambda <Func <int> >(Expression.Default(typeof(int)));
            var l4  = Expression.Lambda <Func <string> >(Expression.Default(typeof(string)));
            var l5  = Expression.Lambda <Func <bool> >(Expression.Default(typeof(bool)));
            var l1  = xgr.FromFunc(l3, l4, l5, (i3, i4, i5) => new MemberInitData()
            {
                FieldOne   = i3,
                FieldTwo   = i4,
                FieldThree = i5,
            });
            var e1 = (MemberInitExpression)l1.Body;
            var e2 = e1.NewExpression;
            var e3 = l3.Body;
            var e4 = l4.Body;
            var e5 = l5.Body;

            var replace = new Dictionary <Expression, Expression>
            {
                { e2, Expression.New(e2.Constructor) },
                { e3, Expression.Constant(1) },
                { e4, Expression.Constant("ABC") },
                { e5, Expression.Constant(true) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.WasNotProduced(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == replace[e2]);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[0]).Expression == replace[e3]);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[1]).Expression == replace[e4]);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[2]).Expression == replace[e5]);
            assert.WasVisited(e2);
            assert.WasProduced(replace[e2]);
            assert.WasNotProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasNotProduced(e3);
            assert.WasVisited(e4);
            assert.WasProduced(replace[e4]);
            assert.WasNotProduced(e4);
            assert.WasVisited(e5);
            assert.WasProduced(replace[e5]);
            assert.WasNotProduced(e5);

            assert.TotalVisits(5);
            assert.TotalProduced(5);
        }
        public virtual void Test060()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                ChildOne =
                {
                    IntTwo    = default(int),
                    IntOne    = default(int),
                    StringTwo = default(string),
                    StringOne = default(string),
                },
                IntOne     = default(int),
                NestedList =
                {
                    new CompareNewBaseTests.NewConstructorData(),
                },
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                IntOne   = default(int),
                ChildOne =
                {
                    IntTwo    = default(int),
                    IntOne    = default(int),
                    StringTwo = default(string),
                    StringOne = default(string),
                },
                NestedList =
                {
                    new CompareNewBaseTests.NewConstructorData(),
                }
            });

            _assert.AreNotEqual(expr1, expr2);
        }
Пример #41
0
        public void Test002()
        {
            var xgr = new ExpressionGenerator();

            var e1 = xgr.MultiProject(
                () => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            },
                x => x.FieldTwo + x.FieldOne,
                x => "GHI" + x.FieldTwo + x.FieldTwo + "DEF",
                (x, y) => new {
                InitializerOneResult = x,
                InitializerTwoResult = y
            }
                );

            var inputPlaceholder = xgr.FromFunc(() => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            });
            var expectations = xgr.FromFunc(inputPlaceholder, x => new {
                InitializerOneResult = x.FieldTwo + x.FieldOne,
                InitializerTwoResult = "GHI" + x.FieldTwo + x.FieldTwo + "DEF"
            });

            var inputParam = Expression.Parameter(inputPlaceholder.ReturnType);
            var expected   = Expression.Lambda(
                ExpressionReplacer.Replace(expectations.Body, inputPlaceholder.Body, inputParam),
                inputParam
                );

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, e1));
        }
        public void Test001()
        {
            var xgr    = new ExpressionGenerator();
            var actual = xgr.FromFunc(() => Environment.GetCommandLineArgs());

            var expected = Expression.Lambda <Func <string[]> >(
                Expression.Call(
                    null,
                    typeof(Environment).GetMethod("GetCommandLineArgs")
                    )
                );

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, actual));
        }
        public void Test002()
        {
            var xgr    = new ExpressionGenerator();
            var actual = xgr.FromFunc(() => paramFunc <int>());

            var expected = Expression.Lambda <Func <int> >(
                Expression.Call(
                    null,
                    typeof(ExpressionGeneratorFromFuncTests).GetMethod("paramFunc").MakeGenericMethod(typeof(int)),
                    Expression.NewArrayInit(typeof(int))
                    )
                );

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, actual));
        }
        public void Test003()
        {
            var xgr    = new ExpressionGenerator();
            var args   = GetIntArgs(1);
            var actual = xgr.FromFunc(args[0], a => paramFunc(a));

            var expected = Expression.Lambda <Func <int> >(
                Expression.Call(
                    null,
                    typeof(ExpressionGeneratorFromFuncTests).GetMethod("paramFunc").MakeGenericMethod(typeof(int)),
                    Expression.NewArrayInit(typeof(int), args.Select(a => a.Body).ToArray())
                    )
                );

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, actual));
        }
        public void Test018()
        {
            var xgr    = new ExpressionGenerator();
            var args   = GetIntArgs(16);
            var actual = xgr.FromFunc(
                args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15],
                (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => paramFunc(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p));

            var expected = Expression.Lambda <Func <int> >(
                Expression.Call(
                    null,
                    typeof(ExpressionGeneratorFromFuncTests).GetMethod("paramFunc").MakeGenericMethod(typeof(int)),
                    Expression.NewArrayInit(typeof(int), args.Select(a => a.Body).ToArray())
                    )
                );

            var comparer = new ExpressionComparer();

            Assert.IsTrue(comparer.AreEqual(expected, actual));
        }
        public virtual void Test030()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new Dictionary<int, int>
            {
                {1, 1},
                {2, 2},
                {3, 3},
            });
            var expr2 = xgr.FromFunc(() => new Dictionary<int, int>
            {
                {1, 1},
                {2, 2},
                {3, 4},
            });

            _assert.AreNotEqual(expr1, expr2);
        }
        public virtual void Test042()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                NestedList = {
                    new CompareNewBaseTests.NewConstructorData(),
                    new CompareNewBaseTests.NewConstructorData(),
                    null,
                }
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                NestedList = {
                    new CompareNewBaseTests.NewConstructorData(),
                    new CompareNewBaseTests.NewConstructorData(),
                    new CompareNewBaseTests.NewConstructorData(),
                }
            });

            _assert.AreNotEqual(expr1, expr2);
        }
        public void Test033()
        {
            var xgr = new ExpressionGenerator();
            var l3 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var e3 = l3.Body as DefaultExpression;
            var l4 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var e4 = l4.Body as DefaultExpression;
            var l1 = xgr.FromFunc(l3, l4, (i3,i4) => new NewData02
            {
                Collection = {
                    i3, i4
                }
            });
            var e1 = l1.Body as MemberInitExpression;
            var e2 = e1.NewExpression;

            var replace = new Dictionary<Expression, Expression> {
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => o1.Bindings[0] is MemberListBinding);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers.Count == ((MemberListBinding)e1.Bindings[0]).Initializers.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[0].Arguments.Count == ((MemberListBinding)e1.Bindings[0]).Initializers[0].Arguments.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[0].Arguments[0] == e3);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[1].Arguments.Count == ((MemberListBinding)e1.Bindings[0]).Initializers[0].Arguments.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[1].Arguments[0] == e4);
            assert.ProductionHas(e1, o1 => o1.NewExpression == e2);
            assert.WasProduced(e1);

            assert.WasVisited(e3);
            assert.WasProduced(e3);
            assert.WasVisited(e4);
            assert.WasProduced(e4);

            assert.TotalVisits(4);
            assert.TotalProduced(4);
        }
        public void Test044()
        {
            var xgr = new ExpressionGenerator();
            var l3 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var e3 = l3.Body as DefaultExpression;
            var l4 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var e4 = l4.Body as DefaultExpression;
            var l5 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var e5 = l5.Body as DefaultExpression;
            var l1 = xgr.FromFunc(l3, l4, l5, (i3, i4, i5) => new NewData02
            {
                Collection = {
                    i3, i4, i5
                }
            });
            var e1 = l1.Body as MemberInitExpression;
            var e2 = e1.NewExpression;

            var replace = new Dictionary<Expression, Expression>
            {
                {e3, Expression.Constant("ABC") },
                {e4, Expression.Constant("DEF") },
                {e5, Expression.Constant("GHI") },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => o1.Bindings[0] is MemberListBinding);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers.Count == ((MemberListBinding)e1.Bindings[0]).Initializers.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[0].Arguments.Count == ((MemberListBinding)e1.Bindings[0]).Initializers[0].Arguments.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[0].Arguments[0] == replace[e3]);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[1].Arguments.Count == ((MemberListBinding)e1.Bindings[0]).Initializers[0].Arguments.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[1].Arguments[0] == replace[e4]);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[2].Arguments.Count == ((MemberListBinding)e1.Bindings[0]).Initializers[0].Arguments.Count);
            assert.ProductionHas(e1, o1 => ((MemberListBinding)o1.Bindings[0]).Initializers[2].Arguments[0] == replace[e5]);
            assert.ProductionHas(e1, o1 => o1.NewExpression == e2);
            assert.WasNotProduced(e1);

            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasVisited(e4);
            assert.WasProduced(replace[e4]);
            assert.WasVisited(e5);
            assert.WasProduced(replace[e5]);
            assert.WasNotProduced(e5);

            assert.TotalVisits(5);
            assert.TotalProduced(5);
        }
        public void Test023()
        {
            var xgr = new ExpressionGenerator();
            var l3 = Expression.Lambda<Func<int>>(Expression.Default(typeof(int)));
            var l4 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var l5 = Expression.Lambda<Func<bool>>(Expression.Default(typeof(bool)));
            var l1 = xgr.FromFunc(l3, l4, l5, (i3, i4, i5) => new MemberInitData()
            {
                FieldOne = i3,
                FieldTwo = i4,
                FieldThree = i5,
            });
            var e1 = (MemberInitExpression)l1.Body;
            var e2 = e1.NewExpression;
            var e3 = l3.Body;
            var e4 = l4.Body;
            var e5 = l5.Body;

            var replace = new Dictionary<Expression, Expression>
            {
                {e2, Expression.New(e2.Constructor) },
                {e3, Expression.Constant(1) },
                {e4, Expression.Constant("ABC") },
                {e5, Expression.Constant(true) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.WasNotProduced(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == replace[e2]);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[0]).Expression == replace[e3]);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[1]).Expression == replace[e4]);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[2]).Expression == replace[e5]);
            assert.WasVisited(e2);
            assert.WasProduced(replace[e2]);
            assert.WasNotProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasNotProduced(e3);
            assert.WasVisited(e4);
            assert.WasProduced(replace[e4]);
            assert.WasNotProduced(e4);
            assert.WasVisited(e5);
            assert.WasProduced(replace[e5]);
            assert.WasNotProduced(e5);

            assert.TotalVisits(5);
            assert.TotalProduced(5);
        }
        public void Test046()
        {
            var xgr = new ExpressionGenerator();
            var l3 = Expression.Lambda<Func<int>>(Expression.Default(typeof(int)));
            var e3 = l3.Body as DefaultExpression;
            var l1 = xgr.FromFunc(l3, (i3) => new NewData02
            {
                NestedOne = {
                    DataOne = i3
                }
            });
            var e1 = l1.Body as MemberInitExpression;
            var e2 = e1.NewExpression;

            var replace = new Dictionary<Expression, Expression>
            {
                {e3, Expression.Constant(1) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == e2);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => o1.Bindings[0] is MemberMemberBinding);
            assert.ProductionHas(e1, o1 => ((MemberMemberBinding)o1.Bindings[0]).Bindings.Count == ((MemberMemberBinding)e1.Bindings[0]).Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberMemberBinding)o1.Bindings[0]).Bindings[0] is MemberAssignment);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)((MemberMemberBinding)o1.Bindings[0]).Bindings[0]).Expression == replace[e3]);
            assert.WasNotProduced(e1);

            assert.WasVisited(e2);
            assert.WasProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasNotProduced(e3);

            assert.TotalVisits(3);
            assert.TotalProduced(3);
        }
        public void Test005()
        {
            var xgr = new ExpressionGenerator();
            var l3 = Expression.Lambda<Func<int>>(Expression.Default(typeof(int)));
            var l4 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var l1 = xgr.FromFunc(l3, l4, (i3, i4) => new MemberInitData()
            {
                FieldOne = i3,
                FieldTwo = i4,
            });
            var e1 = (MemberInitExpression)l1.Body;
            var e2 = e1.NewExpression;
            var e3 = l3.Body;
            var e4 = l4.Body;

            var replace = new Dictionary<Expression, Expression>
            {
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.WasProduced(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == e2);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[0]).Expression == e3);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)o1.Bindings[1]).Expression == e4);
            assert.WasVisited(e2);
            assert.WasProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(e3);
            assert.WasVisited(e4);
            assert.WasProduced(e4);

            assert.TotalVisits(4);
            assert.TotalProduced(4);
        }
        public void Test027()
        {
            var xgr = new ExpressionGenerator();
            var l2 = Expression.Lambda<Func<string>>(Expression.Parameter(typeof(string)));
            var e2 = l2.Body;
            var l3 = Expression.Lambda<Func<int>>(Expression.Parameter(typeof(int)));
            var e3 = l3.Body;
            var l4 = Expression.Lambda<Func<bool>>(Expression.Parameter(typeof(bool)));
            var e4 = l4.Body;
            var l1 = xgr.FromFunc(l2, l3, l4, (v2, v3, v4) => new {
                EleOne = v2,
                EleTwo = v3,
                ElemThree = v4,
            });

            Assert.IsInstanceOfType(l1.Body, typeof(NewExpression));
            Assert.AreEqual(ExpressionType.New, l1.Body.NodeType);
            var e1 = (NewExpression)l1.Body;

            var replace = new Dictionary<Expression, Expression>
            {
                { e2, Expression.Default(typeof(string)) },
                { e3, Expression.Default(typeof(int)) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);
            assert.WasVisited(e1);
            assert.WasNotProduced(e1);
            assert.ProductionHas(e1, o1 => o1.Arguments.Count == e1.Arguments.Count);
            assert.ProductionHas(e1, o1 => o1.Arguments[0] == replace[e2]);
            assert.ProductionHas(e1, o1 => o1.Arguments[1] == replace[e3]);
            assert.ProductionHas(e1, o1 => o1.Arguments[2] == e4);
            assert.ProductionHas(e1, o1 => o1.Constructor == e1.Constructor);
            assert.ProductionHas(e1, o1 => o1.Members.Count == e1.Members.Count);
            assert.ProductionHas(e1, o1 => o1.Members[0] == e1.Members[0]);
            assert.ProductionHas(e1, o1 => o1.Members[1] == e1.Members[1]);
            assert.ProductionHas(e1, o1 => o1.Members[2] == e1.Members[2]);

            assert.WasVisited(e2);
            assert.WasProduced(replace[e2]);
            assert.WasNotProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasNotProduced(e3);
            assert.WasVisited(e4);
            assert.WasProduced(e4);
            assert.TotalVisits(4);
            assert.TotalProduced(4);
        }
        public void Test004()
        {
            var xgr = new ExpressionGenerator();
            var xpr = new ExpressionReader();

            var expr = xgr.FromFunc(() => default(IQueryable<int>).Where(x => x > 10));

            var result = xpr.GetLambda(expr);

            Assert.AreEqual(expr, result);
            Assert.IsInstanceOfType(result, typeof(LambdaExpression));
        }
        public virtual void Test027()
        {
            var xgr = new ExpressionGenerator();

            var expr1 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                ChildOne = {
                }
            });
            var expr2 = xgr.FromFunc(() => new CompareNewBaseTests.NewConstructorData
            {
                ChildOne = {
                }
            });

            _assert.AreEqual(expr1, expr2);
        }
        public virtual void Test015()
        {
            var xgr = new ExpressionGenerator();

            var obj1 = new MethodCallTestData();
            var obj2 = new MethodCallTestData();

            var obj1Expr = Expression.Lambda<Func<MethodCallTestData>>(Expression.Constant(obj1, typeof(MethodCallTestData)));
            var obj2Expr = Expression.Lambda<Func<MethodCallTestData>>(Expression.Constant(obj2, typeof(MethodCallTestData)));

            var expr1 = xgr.FromFunc(obj1Expr, pobj1 => pobj1.IntMethodOne());
            var expr2 = xgr.FromFunc(obj2Expr, pobj2 => pobj2.IntMethodOne());

            _assert.AreNotEqual(expr1, expr2);
        }
        public void Test056()
        {
            var xgr = new ExpressionGenerator();
            var l3 = Expression.Lambda<Func<int>>(Expression.Default(typeof(int)));
            var e3 = l3.Body as DefaultExpression;
            var l4 = Expression.Lambda<Func<string>>(Expression.Default(typeof(string)));
            var e4 = l4.Body as DefaultExpression;
            var l5 = Expression.Lambda<Func<bool>>(Expression.Default(typeof(bool)));
            var e5 = l5.Body as DefaultExpression;
            var l1 = xgr.FromFunc(l3, l4, l5, (i3, i4, i5) => new NewData02
            {
                NestedOne = {
                    DataOne = i3,
                    DataTwo = i4,
                    DataThree = i5,
                }
            });
            var e1 = l1.Body as MemberInitExpression;
            var e2 = e1.NewExpression;

            var replace = new Dictionary<Expression, Expression>
            {
                {e3, Expression.Constant(1) },
                {e5, Expression.Constant(true) },
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);

            assert.WasVisited(e1);
            assert.ProductionHas(e1, o1 => o1.NewExpression == e2);
            assert.ProductionHas(e1, o1 => o1.Bindings.Count == e1.Bindings.Count);
            assert.ProductionHas(e1, o1 => o1.Bindings[0] is MemberMemberBinding);
            assert.ProductionHas(e1, o1 => ((MemberMemberBinding)o1.Bindings[0]).Bindings.Count == ((MemberMemberBinding)e1.Bindings[0]).Bindings.Count);
            assert.ProductionHas(e1, o1 => ((MemberMemberBinding)o1.Bindings[0]).Bindings[0] is MemberAssignment);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)((MemberMemberBinding)o1.Bindings[0]).Bindings[0]).Expression == replace[e3]);
            assert.ProductionHas(e1, o1 => ((MemberMemberBinding)o1.Bindings[0]).Bindings[1] is MemberAssignment);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)((MemberMemberBinding)o1.Bindings[0]).Bindings[1]).Expression == e4);
            assert.ProductionHas(e1, o1 => ((MemberMemberBinding)o1.Bindings[0]).Bindings[2] is MemberAssignment);
            assert.ProductionHas(e1, o1 => ((MemberAssignment)((MemberMemberBinding)o1.Bindings[0]).Bindings[2]).Expression == replace[e5]);
            assert.WasNotProduced(e1);

            assert.WasVisited(e2);
            assert.WasProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(replace[e3]);
            assert.WasNotProduced(e3);
            assert.WasVisited(e4);
            assert.WasProduced(e4);
            assert.WasVisited(e5);
            assert.WasProduced(replace[e5]);
            assert.WasNotProduced(e5);

            assert.TotalVisits(5);
            assert.TotalProduced(5);
        }
        public void Test004()
        {
            var xgr = new ExpressionGenerator();
            var q = Enumerable.Range(0, 1).Select(x => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            }).AsQueryable();

            var e1 = xgr.MultiProject(
                q,
                x => x.FieldTwo + x.FieldOne,
                x => "GHI" + x.FieldTwo + x.FieldTwo + "DEF",
                (x, y) => new {
                    InitializerOneResult = x,
                    InitializerTwoResult = y
                }
            );

            var inputPlaceholder = xgr.FromFunc(() => new {
                FieldOne = 1,
                FieldTwo = "ABC"
            });
            var expectations = xgr.FromFunc(inputPlaceholder, x => new {
                InitializerOneResult = x.FieldTwo + x.FieldOne,
                InitializerTwoResult = "GHI" + x.FieldTwo + x.FieldTwo + "DEF"
            });

            var inputParam = Expression.Parameter(inputPlaceholder.ReturnType);
            var expected = Expression.Lambda(
                ExpressionReplacer.Replace(expectations.Body, inputPlaceholder.Body, inputParam),
                inputParam
            );

            var inner1 = e1.Expression as MethodCallExpression;
            var inner2 = inner1.Arguments[1] as UnaryExpression;
            var inner3 = inner2.Operand as LambdaExpression;

            var comparer = new ExpressionComparer();
            Assert.IsTrue(comparer.AreEqual(expected, inner3));
        }
        public void Test019()
        {
            var xgr = new ExpressionGenerator();
            var l2 = Expression.Lambda<Func<string>>(Expression.Parameter(typeof(string)));
            var e2 = l2.Body;
            var l3 = Expression.Lambda<Func<int>>(Expression.Parameter(typeof(int)));
            var e3 = l3.Body;
            var l1 = xgr.FromFunc(l2, l3, (v2, v3) => new {
                EleOne = v2,
                EleTwo = v3
            });

            Assert.IsInstanceOfType(l1.Body, typeof(NewExpression));
            Assert.AreEqual(ExpressionType.New, l1.Body.NodeType);
            var e1 = (NewExpression)l1.Body;

            var replace = new Dictionary<Expression, Expression>
            {
            };
            var assert = ExpressionVisitorVerifierTool.Test(e1, replace);
            assert.WasVisited(e1);
            assert.WasProduced(e1);
            assert.ProductionHas(e1, o1 => o1.Arguments.Count == e1.Arguments.Count);
            assert.ProductionHas(e1, o1 => o1.Arguments[0] == e2);
            assert.ProductionHas(e1, o1 => o1.Arguments[1] == e3);
            assert.ProductionHas(e1, o1 => o1.Constructor == e1.Constructor);
            assert.ProductionHas(e1, o1 => o1.Members.Count == e1.Members.Count);
            assert.ProductionHas(e1, o1 => o1.Members[0] == e1.Members[0]);
            assert.ProductionHas(e1, o1 => o1.Members[1] == e1.Members[1]);

            assert.WasVisited(e2);
            assert.WasProduced(e2);
            assert.WasVisited(e3);
            assert.WasProduced(e3);
            assert.TotalVisits(3);
            assert.TotalProduced(3);
        }
        public virtual void Test016()
        {
            var xgr = new ExpressionGenerator();

            MethodCallTestData obj1 = new MethodCallTestData();
            MethodCallTestData obj2 = new MethodCallTestData();

            var expr1 = xgr.FromFunc(() => obj1.IntMethodOne());
            var expr2 = xgr.FromFunc(() => obj2.IntMethodOne());

            // these aren't equal because the expressions (.NET 3.5 -> .nET 4.5.2+) are generated as a member access
            // on a constant over the invisible closure, instead of a constant reference to the objects themselves
            // TODO: Keep this up to date as new versions are released
            _assert.AreNotEqual(expr1, expr2);
        }