Example #1
0
        private MethodInvocationContext GetMethodArgs(MethodCallExpression methodExpression)
        {
            MethodInvocationContext context = new MethodInvocationContext();

            foreach (var arg in methodExpression.Arguments)
            {
                switch (arg.NodeType)
                {
                case ExpressionType.Call:

                    MethodCallExpression paramCall = arg as MethodCallExpression;

                    // Extract the data source type
                    Type     sourceType  = ExtractDatasourceType(paramCall);
                    Object[] factoryArgs = ExtractDatasourceParameters(paramCall);

                    context.AddArgumentSource(sourceType, factoryArgs);

                    break;

                case ExpressionType.Constant:

                    // Simply pop the constant into the list
                    ConstantExpression paramConstant = arg as ConstantExpression;
                    context.AddArgumentValue(paramConstant);
                    break;

                default:
                    throw new ArgumentException("Unsupported argument used in method invocation list", "methodExpression");
                }
            }

            return(context);
        }
        public void AddArgumentSource_AddsArgument()
        {
            MethodInvocationContext context = new MethodInvocationContext();
            context.AddArgumentSource(typeof(RandomStringSource));

            DatasourceFactory factory = context.GetArguments().First();
            Assert.NotNull(factory);
        }