Пример #1
0
        internal static MethodCall SetupSet(Mock mock, LambdaExpression expression, Expression valueExpression)
        {
            var prop = expression.ToPropertyInfo();

            Guard.CanWrite(prop);

            var propSet = prop.GetSetMethod(true);

            ThrowIfSetupExpressionInvolvesUnsupportedMember(expression, propSet);
            ThrowIfSetupMethodNotVisibleToProxyFactory(propSet);

            var setup      = new MethodCall(mock, null, expression, propSet, new[] { valueExpression });
            var targetMock = GetTargetMock(((MemberExpression)expression.Body).Expression, mock);

            targetMock.Setups.Add(setup);

            return(setup);
        }
Пример #2
0
        internal static SetterMethodCall <T, TProperty> SetupSet <T, TProperty>(
            Mock mock,
            Expression <Func <T, TProperty> > expression, TProperty value)
            where T : class
        {
            var prop = expression.ToPropertyInfo();

            Guard.CanWrite(prop);

            var setter = prop.SetMethod;

            ThrowIfSetupExpressionInvolvesUnsupportedMember(expression, setter);

            var setup      = new SetterMethodCall <T, TProperty>(mock, expression, setter, value);
            var targetMock = GetTargetMock(((MemberExpression)expression.Body).Expression, mock);

            targetMock.Setups.Add(setup);

            return(setup);
        }
Пример #3
0
        internal static SetterMethodCall <T, TProperty> SetupSet <T, TProperty>(
            Mock <T> mock,
            Expression <Func <T, TProperty> > expression)
            where T : class
        {
            var prop = expression.ToPropertyInfo();

            Guard.CanWrite(prop);

            var propSet = prop.GetSetMethod(true);

            ThrowIfSetupExpressionInvolvesUnsupportedMember(expression, propSet);
            ThrowIfSetupMethodNotVisibleToProxyFactory(propSet);

            var setup      = new SetterMethodCall <T, TProperty>(mock, expression, propSet);
            var targetMock = GetTargetMock(((MemberExpression)expression.Body).Expression, mock);

            targetMock.Setups.Add(setup);

            return(setup);
        }