public void VisitUnknownExpression_NotEvaluatable() { var expression = new SubQueryExpression(ExpressionHelper.CreateQueryModel <Cook>()); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.False); }
public static Expression ExtractParameters(Expression expressionTree, QueryContext queryContext) { var partialEvaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expressionTree); var visitor = new ParameterExtractingExpressionTreeVisitor(partialEvaluationInfo, queryContext); return(visitor.VisitExpression(expressionTree)); }
public void VisitUnknownExpression_Ignored() { var expression = new UnknownExpression(typeof(object)); var result = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(result.IsEvaluatableExpression(expression), Is.False); }
public void ParameterExpression_IsNotEvaluatable() { var expression = ExpressionHelper.CreateParameterExpression(); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.False); }
public void SimpleExpression_IsEvaluatable() { var expression = Expression.Constant(0); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.True); }
/// <summary> /// Takes an expression tree and finds and evaluates all its evaluatable subtrees. /// </summary> public static Expression EvaluateIndependentSubtrees(Expression expressionTree) { var partialEvaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expressionTree); var visitor = new PartialEvaluatingExpressionTreeVisitor(expressionTree, partialEvaluationInfo); return(visitor.VisitExpression(expressionTree)); }
public void MemberExpression_WithIQueryableObject_IsNotEvaluatable() { var source = new QueryableFakeWithCount <int>(); var expression = ExpressionHelper.MakeExpression(() => source.Count); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.False); }
public void MethodCall_WithIQueryableParameter_IsNotEvaluatable() { var source = ExpressionHelper.CreateQueryable <Cook> (); var expression = ExpressionHelper.MakeExpression(() => source.Count()); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.False); }
public static Expression EvaluateIndependentSubtrees(Expression expressionTree) { ArgumentUtility.CheckNotNull("expressionTree", expressionTree); var partialEvaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expressionTree); return (new CustomPartialEvaluatingExpressionTreeVisitor(expressionTree, partialEvaluationInfo).VisitExpression( expressionTree)); }
public void PartialEvaluationExceptionExpression_NotEvaluable_AndChildrenNeither() { var inner = Expression.Constant(0); var partialEvaluationExceptionExpression = new PartialEvaluationExceptionExpression(new Exception(), inner); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(partialEvaluationExceptionExpression); Assert.That(evaluationInfo.IsEvaluatableExpression(partialEvaluationExceptionExpression), Is.False); Assert.That(evaluationInfo.IsEvaluatableExpression(inner), Is.False); }
public void VisitExtensionExpression_NotEvaluatable_ButChildrenMayBe() { var innerExpression = Expression.MakeBinary(ExpressionType.Equal, Expression.Constant(0), Expression.Constant(0)); var extensionExpression = new TestExtensionExpression(innerExpression); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(extensionExpression); Assert.That(evaluationInfo.IsEvaluatableExpression(extensionExpression), Is.False); Assert.That(evaluationInfo.IsEvaluatableExpression(innerExpression), Is.True); }
public void MemberInitialization_WithoutParametersInMemberAssignments_IsEvaluatable() { var expression = (MemberInitExpression)ExpressionHelper.MakeExpression <int, AnonymousType> (i => new AnonymousType { a = 1, b = 1 }); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.True); Assert.That(evaluationInfo.IsEvaluatableExpression(expression.NewExpression), Is.True); }
public void ListInitialization_WithoutParametersInMemberAssignments_IsEvaluatable() { var expression = (ListInitExpression)ExpressionHelper.MakeExpression <int, List <int> > (i => new List <int> { 2, 1 }); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.True); Assert.That(evaluationInfo.IsEvaluatableExpression(expression.NewExpression), Is.True); }
public void ParameterExpression_SiblingCanBeEvaluatable() { var expression = Expression.MakeBinary( ExpressionType.Equal, ExpressionHelper.CreateParameterExpression(), Expression.Constant(0)); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression.Right), Is.True); }
public void ExpressionContainingParameterExpression_IsNotEvaluatable() { var expression = Expression.MakeBinary( ExpressionType.Equal, ExpressionHelper.CreateParameterExpression(), ExpressionHelper.CreateParameterExpression()); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.IsEvaluatableExpression(expression), Is.False); }
public void NestedExpression_InnerAndOuterAreEvaluatable() { var innerExpressionLeft = Expression.Constant(0); var innerExpressionRight = Expression.Constant(0); var outerExpression = Expression.MakeBinary(ExpressionType.Add, innerExpressionLeft, innerExpressionRight); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(outerExpression); Assert.That(evaluationInfo.IsEvaluatableExpression(outerExpression), Is.True); Assert.That(evaluationInfo.IsEvaluatableExpression(innerExpressionLeft), Is.True); Assert.That(evaluationInfo.IsEvaluatableExpression(innerExpressionRight), Is.True); }
public void NullExpression_InOtherExpression_IsIgnored() { var expression = Expression.MakeBinary( ExpressionType.Equal, ExpressionHelper.CreateParameterExpression(), ExpressionHelper.CreateParameterExpression()); Assert.That(expression.Conversion, Is.Null); var evaluationInfo = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(expression); Assert.That(evaluationInfo.Count, Is.EqualTo(0)); }
public void VisitDynamicExpression_WithParameterReference_NonEvaluable() { var parameterExpression = Expression.Parameter(typeof(object), "x"); var dynamicExpressionWithParameterReference = Expression.Dynamic( Binder.GetMember( CSharpBinderFlags.InvokeSimpleName, "colour", typeof(object), new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }), typeof(object), parameterExpression); var body = Expression.MakeBinary(ExpressionType.Equal, dynamicExpressionWithParameterReference, Expression.Constant("orange")); var result = EvaluatableTreeFindingExpressionTreeVisitor.Analyze(body); Assert.That(result.IsEvaluatableExpression(body), Is.False); }