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); }
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); }
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); }