Esempio n. 1
0
        internal static IArgumentValidator GetArgumentValidatorForArgument(MethodCallExpression expression)
        {
            var argumentsForConstructor = expression.Arguments.Skip(1).Select(x => ExpressionManager.GetValueProducedByExpression(x)).ToArray();
            var validatorType           = GetValidatorType(expression);

            AssertValidatorTypeImplementsArgumentValidatorInterface(validatorType);

            EnsureThatValidatorConstructorMatchesSignatureOfExtensionMethod(expression.Method, validatorType);

            var validator = (IArgumentValidator)Activator.CreateInstance(validatorType, argumentsForConstructor);


            return(validator);
        }
Esempio n. 2
0
        public static T Fake <T>(Expression <Func <T> > constructorCall) where T : class
        {
            Guard.IsNotNull(constructorCall, "constructorCall");

            if (constructorCall.Body.NodeType != ExpressionType.New)
            {
                throw new ArgumentException(ExceptionMessages.NonConstructorExpressionMessage);
            }

            var constructorArguments =
                (from argument in ((NewExpression)constructorCall.Body).Arguments
                 select ExpressionManager.GetValueProducedByExpression(argument)).ToArray();

            return((T) new FakeObject(typeof(T), constructorArguments).Object);
        }