public void Transform_ChildrenTransformedBeforeParent()
        {
            var inputChildExpression       = CreateSimpleExpression(0);
            var transformedChildExpression = CreateSimpleExpression(1);

            var inputParentExpression       = Expression.UnaryPlus(inputChildExpression);
            var transformedParentExpression = CreateSimpleExpression(2);

            var providerMock = MockRepository.GenerateStrictMock <IExpressionTranformationProvider> ();

            providerMock
            .Expect(mock => mock.GetTransformations(inputChildExpression))
            .Return(new ExpressionTransformation[] { expr => transformedChildExpression });
            providerMock
            .Expect(mock => mock.GetTransformations(transformedChildExpression))
            .Return(new ExpressionTransformation[0]);
            providerMock
            .Expect(mock => mock.GetTransformations(
                        Arg <Expression> .Matches(expr => expr is UnaryExpression && ((UnaryExpression)expr).Operand == transformedChildExpression)))
            .Return(new ExpressionTransformation[] { expr => transformedParentExpression });
            providerMock
            .Expect(mock => mock.GetTransformations(transformedParentExpression))
            .Return(new ExpressionTransformation[0]);
            providerMock.Replay();

            var result = TransformingExpressionVisitor.Transform(inputParentExpression, providerMock);

            providerMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(transformedParentExpression));
        }
        public void Transform_NullExpression()
        {
            var providerMock = MockRepository.GenerateStrictMock <IExpressionTranformationProvider> ();

            providerMock.Replay();

            var result = TransformingExpressionVisitor.Transform(null, providerMock);

            providerMock.VerifyAllExpectations();
            Assert.That(result, Is.Null);
        }
        public void Transform_NoMatchingTransformation()
        {
            var inputExpression = CreateSimpleExpression(0);

            var providerMock = MockRepository.GenerateStrictMock <IExpressionTranformationProvider> ();

            providerMock
            .Expect(mock => mock.GetTransformations(inputExpression))
            .Return(new ExpressionTransformation[0]);
            providerMock.Replay();

            var result = TransformingExpressionVisitor.Transform(inputExpression, providerMock);

            providerMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(inputExpression));
        }
        public void Transform_TwoMatchingTransformations_FirstTransformationChangesExpression()
        {
            var inputExpression       = CreateSimpleExpression(0);
            var transformedExpression = CreateSimpleExpression(0);

            var providerMock = MockRepository.GenerateStrictMock <IExpressionTranformationProvider> ();

            providerMock
            .Expect(mock => mock.GetTransformations(inputExpression))
            .Return(new ExpressionTransformation[] {
                expr => transformedExpression,
                expr => { throw new InvalidOperationException("Must not be called."); }
            });
            providerMock
            .Expect(mock => mock.GetTransformations(transformedExpression))
            .Return(new ExpressionTransformation[0]);
            providerMock.Replay();

            var result = TransformingExpressionVisitor.Transform(inputExpression, providerMock);

            providerMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(transformedExpression));
        }
        public Expression Process(Expression expressionTree)
        {
            ArgumentUtility.CheckNotNull("expressionTree", expressionTree);

            return(TransformingExpressionVisitor.Transform(expressionTree, Provider));
        }