public void Visit_Null()
        {
            var visitor = new DelegateBasedExpressionVisitor(exp => { Assert.Fail("Should not be called."); return(null); });

            var result = visitor.Visit(node: null);

            Assert.That(result, Is.Null);
        }
        public void Visit_Changes()
        {
            var fakeExpression = ExpressionTreeObjectMother.GetSomeExpression();
            Func <Expression, Expression> delegate_ = exp => fakeExpression;
            var visitor = new DelegateBasedExpressionVisitor(delegate_);

            var expression = ExpressionTreeObjectMother.GetSomeExpression();

            var result = visitor.Visit(expression);

            Assert.That(result, Is.SameAs(fakeExpression));
        }
        public void Visit_NoChanges()
        {
            var visitedExpressions = new List <Expression>();
            Func <Expression, Expression> delegate_ = exp =>
            {
                visitedExpressions.Add(exp);
                return(exp);
            };
            var visitor = new DelegateBasedExpressionVisitor(delegate_);

            var expression1     = ExpressionTreeObjectMother.GetSomeExpression();
            var expression2     = ExpressionTreeObjectMother.GetSomeExpression();
            var blockExpression = Expression.Block(expression1, expression2);

            var result = visitor.Visit(blockExpression);

            Assert.That(result, Is.SameAs(blockExpression));
            Assert.That(visitedExpressions, Is.EqualTo(new[] { expression1, expression2, blockExpression }));
        }