Ejemplo n.º 1
0
        public void Transform_ArgumentIsNull()
        {
            var method           = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
            var objectExpression = Expression.Constant("Test");
            var argument1        = Expression.Constant(null, typeof(string));
            var expression       = Expression.Call(objectExpression, method, argument1);
            var transformer      = new StartsWithMethodCallTransformer();

            var result = transformer.Transform(expression);

            SqlExpressionTreeComparer.CheckAreEqualTrees(Expression.Constant(false), result);
        }
Ejemplo n.º 2
0
        public void Transform_ArgumentIsNotNull()
        {
            var method           = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
            var objectExpression = Expression.Constant("Test");
            var argument1        = Expression.Constant("test");
            var expression       = Expression.Call(objectExpression, method, argument1);
            var transformer      = new StartsWithMethodCallTransformer();
            var result           = transformer.Transform(expression);

            var rightExpression = Expression.Constant(string.Format("{0}%", argument1.Value));

            var expectedResult = new SqlLikeExpression(objectExpression, rightExpression, new SqlLiteralExpression(@"\"));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }
Ejemplo n.º 3
0
        public void Transform_ArgumentIsNotNullAndIsNoConstantValue_()
        {
            var method           = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
            var objectExpression = Expression.Constant("Test");
            var argument1        = Expression.MakeMemberAccess(Expression.Constant(new Cook()), typeof(Cook).GetProperty("Name"));
            var expression       = Expression.Call(objectExpression, method, argument1);
            var transformer      = new StartsWithMethodCallTransformer();

            var result = transformer.Transform(expression);

            Expression rightExpression = new SqlFunctionExpression(
                typeof(string),
                "REPLACE",
                new SqlFunctionExpression(
                    typeof(string),
                    "REPLACE",
                    new SqlFunctionExpression(
                        typeof(string),
                        "REPLACE",
                        new SqlFunctionExpression(
                            typeof(string),
                            "REPLACE",
                            argument1,
                            new SqlLiteralExpression(@"\"),
                            new SqlLiteralExpression(@"\\")),
                        new SqlLiteralExpression(@"%"),
                        new SqlLiteralExpression(@"\%")),
                    new SqlLiteralExpression(@"_"),
                    new SqlLiteralExpression(@"\_")),
                new SqlLiteralExpression(@"["),
                new SqlLiteralExpression(@"\["));

            rightExpression = Expression.Add(
                rightExpression, new SqlLiteralExpression("%"), typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) }));
            var expectedResult = new SqlLikeExpression(objectExpression, rightExpression, new SqlLiteralExpression(@"\"));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedResult, result);
        }