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)); }
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); }
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)); } }
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); }
protected void AssertCompileException(string expression, ExpressionContext context, BoundExpressionOptions options) { try { new DynamicExpression(expression, Language).Bind(context, options); Assert.True(false, "Compile exception expected"); } catch { } }
protected void Resolve(string expression, object expected, BoundExpressionOptions options) { Resolve(null, expression, expected, options); }
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); }
public BoundExpression GetOrCreateBoundExpression(IBindingContext binder, BoundExpressionOptions options) { return(_boundExpressionCache.GetOrCreateBoundExpression(binder, options)); }
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)); }
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())); } }
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()); } }