public void VisitExtensionExpression ()
    {
      var expression = new TestExtensionExpression (Expression.Constant (0));
      var result = FormattingExpressionTreeVisitor.Format (expression);

      Assert.That (result, Is.EqualTo ("Test(0)"));
    }
    public void VisitExtensionExpression_ReducedExpressionIsVisited ()
    {
      ExpressionTreeVisitor visitor = new TestThrowingConstantExpressionTreeVisitor();
      var constantExpression = Expression.Constant (0);
      var expression = new TestExtensionExpression (constantExpression);

      var result = visitor.VisitExpression (expression);

      Assert.That (result, Is.Not.SameAs (constantExpression));
      Assert.That (((ConstantExpression) result).Value, Is.EqualTo("ConstantExpression was visited"));
    }
Пример #3
0
    public void IsSupportedStandardExpression_False ()
    {
      var extensionExpression = new TestExtensionExpression (Expression.Constant (0));
      Assert.That (ExpressionTreeVisitor.IsSupportedStandardExpression (extensionExpression), Is.False);

      var unknownExpression = new UnknownExpression (typeof (int));
      Assert.That (ExpressionTreeVisitor.IsSupportedStandardExpression (unknownExpression), Is.False);

      var querySourceReferenceExpression = new QuerySourceReferenceExpression (ExpressionHelper.CreateMainFromClause_Int());
      Assert.That (ExpressionTreeVisitor.IsSupportedStandardExpression (querySourceReferenceExpression), Is.False);

      var subQueryExpression = new SubQueryExpression (ExpressionHelper.CreateQueryModel<Cook>());
      Assert.That (ExpressionTreeVisitor.IsSupportedStandardExpression (subQueryExpression), Is.False);
    }
    public void ApplyContext_SemanticsPropagatedToChildExpressionsByDefault ()
    {
      var expressionOfCorrectType = new TestExtensionExpression (new TestExtensionExpressionWithoutChildren (typeof (bool)));
      var expressionOfIncorrectType =
          new TestExtensionExpression (new SqlConvertedBooleanExpression (new TestExtensionExpressionWithoutChildren (typeof (int))));

      var result1 = _predicateRequiredVisitor.VisitExpression (expressionOfCorrectType);
      var result2 = _predicateRequiredVisitor.VisitExpression (expressionOfIncorrectType);

      Assert.That (result1, Is.SameAs (expressionOfCorrectType));

      var expectedResult2 = new TestExtensionExpression (
          Expression.Equal (((SqlConvertedBooleanExpression) expressionOfIncorrectType.Expression).Expression, new SqlLiteralExpression (1)));
      SqlExpressionTreeComparer.CheckAreEqualTrees (expectedResult2, result2);
    }
    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 VisitExtensionExpression_ChildrenAreProcessed ()
    {
      // new TestExtensionExpression (new AnonymousType ( a = 5 ).a) => new TestExtensionExpression (5)
      var memberExpression = Expression.MakeMemberAccess (
          _anonymousTypeNewExpressionWithAssignments,
          _anonymousTypeA);
      var extensionExpression = new TestExtensionExpression (memberExpression);

      var result = TransparentIdentifierRemovingExpressionTreeVisitor.ReplaceTransparentIdentifiers (extensionExpression);

      var expectedExpression = new TestExtensionExpression (_assignedExpressionA);
      ExpressionTreeComparer.CheckAreEqualTrees (expectedExpression, result);
    }
    public void VisitExtensionExpression ()
    {
      var innerExpression = Expression.MakeBinary (ExpressionType.Equal, Expression.Constant (0), Expression.Constant (0));
      var extensionExpression = new TestExtensionExpression (innerExpression);
      
      var result = PartialEvaluatingExpressionTreeVisitor.EvaluateIndependentSubtrees (extensionExpression);

      var expected = new TestExtensionExpression (Expression.Constant (true));
      ExpressionTreeComparer.CheckAreEqualTrees (expected, result);
    }
    public void VisitExtensionExpression_ChildrenAreProcessed ()
    {
      var extensionExpression = new TestExtensionExpression (new QuerySourceReferenceExpression (_oldFromClause));

      var result = (TestExtensionExpression) ReferenceReplacingExpressionTreeVisitor.ReplaceClauseReferences (extensionExpression, _querySourceMapping, true);

      var expectedExpression = new TestExtensionExpression (new QuerySourceReferenceExpression (_newFromClause));
      ExpressionTreeComparer.CheckAreEqualTrees (expectedExpression, result);
    }
 public void CreateExpressionNode_InvalidNodeParameterType ()
 {
   var selector = new TestExtensionExpression (Expression.Constant (0));
   MethodCallExpressionNodeFactory.CreateExpressionNode (typeof (SelectExpressionNode), _parseInfo, new object[] { selector });
 }