/// <summary>
        /// If this is one of our Invoke method calls, then we can try to do expression replacement.
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public Expression Transform(MethodCallExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            //
            // Fail quickly if this isn't something we are interested in.
            //

            if (expression.Object != null ||
                expression.Method.Name != "Invoke")
            {
                return(expression);
            }

            if (expression.Method.DeclaringType != typeof(Helpers))
            {
                return(expression);
            }

            //
            // Ok, this is real. Get the expression. The compiler should make sure that
            // all types match properly.
            //

            var exprFinder = new ExpressionFunctionExpander();
            var expanded   = exprFinder.Visit(expression);
            var result     = new PartialEvaluatingExpressionTreeProcessor(new EvaluatableExpressionFilterAll()).Process(expanded);

            return(result);
        }
        public void Process()
        {
            var expression = Expression.Add(Expression.Constant(1), Expression.Constant(1));
            var processor  = new PartialEvaluatingExpressionTreeProcessor();

            var result = processor.Process(expression);

            Assert.That(result, Is.TypeOf(typeof(ConstantExpression)));
            Assert.That(((ConstantExpression)result).Value, Is.EqualTo(2));
        }
        public void Process_WithFilter_PassesIntoVisitor()
        {
            var expression = Expression.Constant(1);

            var filterMock = MockRepository.GenerateStrictMock <IEvaluatableExpressionFilter>();

            filterMock.Expect(_ => _.IsEvaluatableConstant(expression)).Return(true);
            filterMock.Replay();

            var processor = new PartialEvaluatingExpressionTreeProcessor(filterMock);

            var result = processor.Process(expression);

            Assert.That(result, Is.SameAs(expression));
            filterMock.VerifyAllExpectations();
        }