Beispiel #1
0
        public void TestValueTypeOwner()
        {
            TestStruct        owner   = new TestStruct(100);
            ExpressionContext context = this.CreateGenericContext(owner);
            var options = new BoundExpressionOptions
            {
                AllowPrivateAccess = true
            };

            var e      = new DynamicExpression <int>("mya.compareto(100)", ExpressionLanguage.Flee);
            int result = e.Invoke(context, options);

            Assert.AreEqual(0, result);

            e      = new DynamicExpression <int>("myA", ExpressionLanguage.Flee);
            result = e.Invoke(context, options);
            Assert.AreEqual(100, result);

            e      = new DynamicExpression <int>("DoStuff()", ExpressionLanguage.Flee);
            result = e.Invoke(context);
            Assert.AreEqual(100, result);

            DateTime dt = DateTime.Now;

            context = this.CreateGenericContext(dt);

            e      = new DynamicExpression <int>("Month", ExpressionLanguage.Flee);
            result = e.Invoke(context);
            Assert.AreEqual(dt.Month, result);

            var e2 = new DynamicExpression <string>("tolongdatestring()", ExpressionLanguage.Flee);

            Assert.AreEqual(dt.ToLongDateString(), e2.Invoke(context));
        }
Beispiel #2
0
        private void DoTestInvalidExpressions(string[] arr)
        {
            var reason = (ExpressionsExceptionType)Enum.Parse(typeof(ExpressionsExceptionType), arr[2], true);

            var options = new BoundExpressionOptions
            {
                ResultType = Type.GetType(arr[0], true, true),
                AllowPrivateAccess = true
            };

            AssertCompileException(arr[1], MyGenericContext, options, reason);
        }
Beispiel #3
0
        private void DoTestInvalidExpressions(string[] arr)
        {
            var reason = (ExpressionsExceptionType)Enum.Parse(typeof(ExpressionsExceptionType), arr[2], true);

            var options = new BoundExpressionOptions
            {
                ResultType         = Type.GetType(arr[0], true, true),
                AllowPrivateAccess = true
            };

            AssertCompileException(arr[1], MyGenericContext, options, reason);
        }
Beispiel #4
0
        protected void Resolve(ExpressionContext expressionContext, string expression, object expected, BoundExpressionOptions options)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");

            object actual = new DynamicExpression(
                expression,
                ExpressionLanguage.Flee
            ).Invoke(
                expressionContext ?? new ExpressionContext(),
                options
            );

            Assert.AreEqual(expected, actual);
        }
 protected void AssertCompileException(string expression, ExpressionContext context, BoundExpressionOptions options, ExpressionsExceptionType exceptionType)
 {
     try
     {
         new DynamicExpression(expression, Language).Bind(context, options);
         Assert.Fail("Compile exception expected");
     }
     catch (ExpressionsException ex)
     {
         Assert.AreEqual(exceptionType, ex.Type, string.Format("Expected exception type '{0}' but got '{1}'", exceptionType, ex.Type));
     }
 }
Beispiel #6
0
        protected void AssertCompileException(string expression, ExpressionContext context, BoundExpressionOptions options, ExpressionsExceptionType exceptionType)
        {
            try
            {
                var dynamicExpressions = new DynamicExpression(expression, Language);
                dynamicExpressions.Bind(context, options);

                Assert.True(false, "Compile exception expected");
            }
            catch (ExpressionsException ex)
            {
                Assert.Equal(exceptionType, ex.Type);
            }
        }
 protected void AssertCompileException(string expression, ExpressionContext context, BoundExpressionOptions options)
 {
     try
     {
         new DynamicExpression(expression, Language).Bind(context, options);
         Assert.Fail("Compile exception expected");
     }
     catch
     {
     }
 }
 private void Resolve(string expression, ExpressionsExceptionType exceptionType, BoundExpressionOptions options)
 {
     Resolve(null, expression, exceptionType, options);
 }
Beispiel #9
0
 protected void AssertCompileException(string expression, ExpressionContext context, BoundExpressionOptions options)
 {
     try
     {
         new DynamicExpression(expression, Language).Bind(context, options);
         Assert.True(false, "Compile exception expected");
     }
     catch
     {
     }
 }
Beispiel #10
0
 protected void Resolve(string expression, object expected, BoundExpressionOptions options)
 {
     Resolve(null, expression, expected, options);
 }
Beispiel #11
0
        protected void Resolve(ExpressionContext expressionContext, string expression, object expected, BoundExpressionOptions options)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            object actual = new DynamicExpression(
                expression,
                ExpressionLanguage.Csharp
                ).Invoke(
                expressionContext ?? new ExpressionContext(),
                options
                );

            Assert.AreEqual(expected, actual);
        }
Beispiel #12
0
 protected void AssertCompileException(string expression, ExpressionContext context, BoundExpressionOptions options, ExpressionsExceptionType exceptionType)
 {
     try
     {
         new DynamicExpression(expression, Language).Bind(context, options);
         Assert.Fail("Compile exception expected");
     }
     catch (ExpressionsException ex)
     {
         Assert.AreEqual(exceptionType, ex.Type, string.Format("Expected exception type '{0}' but got '{1}'", exceptionType, ex.Type));
     }
 }
Beispiel #13
0
 public BoundExpression GetOrCreateBoundExpression(IBindingContext binder, BoundExpressionOptions options)
 {
     return(_boundExpressionCache.GetOrCreateBoundExpression(binder, options));
 }
Beispiel #14
0
 protected void Resolve(string expression, object expected, BoundExpressionOptions options)
 {
     Resolve(null, expression, expected, options);
 }
Beispiel #15
0
        public void TestValueTypeOwner()
        {
            TestStruct owner = new TestStruct(100);
            ExpressionContext context = this.CreateGenericContext(owner);
            var options = new BoundExpressionOptions
            {
                AllowPrivateAccess = true
            };

            var e = new DynamicExpression<int>("mya.compareto(100)", ExpressionLanguage.Flee);
            int result = e.Invoke(context, options);
            Assert.AreEqual(0, result);

            e = new DynamicExpression<int>("myA", ExpressionLanguage.Flee);
            result = e.Invoke(context, options);
            Assert.AreEqual(100, result);

            e = new DynamicExpression<int>("DoStuff()", ExpressionLanguage.Flee);
            result = e.Invoke(context);
            Assert.AreEqual(100, result);

            DateTime dt = DateTime.Now;
            context = this.CreateGenericContext(dt);

            e = new DynamicExpression<int>("Month", ExpressionLanguage.Flee);
            result = e.Invoke(context);
            Assert.AreEqual(dt.Month, result);

            var e2 = new DynamicExpression<string>("tolongdatestring()", ExpressionLanguage.Flee);
            Assert.AreEqual(dt.ToLongDateString(), e2.Invoke(context));
        }
Beispiel #16
0
 private void Resolve(ExpressionContext context, string expression, ExpressionsExceptionType exceptionType, BoundExpressionOptions options)
 {
     try
     {
         Resolve(context, expression, null, options);
         Assert.True(false, string.Format("Expected exception type '{0}'", exceptionType));
     }
     catch (ExpressionsException ex)
     {
         Assert.Equal(exceptionType, ex.Type);
     }
     catch (Exception ex)
     {
         Assert.True(false, string.Format("Expected ExpressionsException got '{0}'", ex.GetType()));
     }
 }
Beispiel #17
0
 private void Resolve(string expression, ExpressionsExceptionType exceptionType, BoundExpressionOptions options)
 {
     Resolve(null, expression, exceptionType, options);
 }
 private void Resolve(ExpressionContext context, string expression, ExpressionsExceptionType exceptionType, BoundExpressionOptions options)
 {
     try
     {
         Resolve(context, expression, null, options);
         Assert.Fail("Expected exception type '{0}'", exceptionType);
     }
     catch (ExpressionsException ex)
     {
         Assert.AreEqual(exceptionType, ex.Type, String.Format("Expected exception type '{0}' got '{1}'", exceptionType, ex.Type));
     }
     catch (Exception ex)
     {
         Assert.Fail("Expected ExpressionsException got '{0}'", ex.GetType());
     }
 }