Beispiel #1
0
Datei: Mock.cs Projekt: lxf/moq4
        /// <summary>
        /// Gets the interceptor target for the given expression and root mock,
        /// building the intermediate hierarchy of mock objects if necessary.
        /// </summary>
        private static Interceptor GetInterceptor(Expression fluentExpression, Mock mock)
        {
            var targetExpression = FluentMockVisitor.Accept(fluentExpression, mock);
            var targetLambda     = Expression.Lambda <Func <Mock> >(Expression.Convert(targetExpression, typeof(Mock)));

            var targetObject = targetLambda.Compile()();

            return(targetObject.Interceptor);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the interceptor target for the given expression and root mock,
        /// building the intermediate hierarchy of mock objects if necessary.
        /// </summary>
        private static Mock GetTargetMock(Expression fluentExpression, Mock mock)
        {
            if (fluentExpression is ParameterExpression)
            {
                // fast path for single-dot setup expressions;
                // no need for expensive lambda compilation.
                return(mock);
            }

            var targetExpression = FluentMockVisitor.Accept(fluentExpression, mock);
            var targetLambda     = Expression.Lambda <Func <Mock> >(Expression.Convert(targetExpression, typeof(Mock)));

            var targetObject = targetLambda.Compile()();

            return(targetObject);
        }