/// <summary>
 /// Construct a <see cref="VirtualMethodReturn"/> instance that returns
 /// a value.
 /// </summary>
 /// <param name="originalInvocation">The method invocation.</param>
 /// <param name="returnValue">Return value (should be null if method returns void).</param>
 /// <param name="arguments">All arguments (including current values) passed to the method.</param>
 public VirtualMethodReturn(IMethodInvocation originalInvocation, object returnValue, object[] arguments)
 {
     invocationContext = originalInvocation.InvocationContext;
     this.returnValue = returnValue;
     outputs = new ParameterCollection(arguments, originalInvocation.MethodBase.GetParameters(),
         delegate(ParameterInfo pi) { return pi.ParameterType.IsByRef; });
 }
 /// <summary>
 /// Creates a new <see cref="TransparentProxyMethodReturn"/> object that contains an
 /// exception thrown by the target.
 /// </summary>
 /// <param name="ex">Exception that was thrown.</param>
 /// <param name="callMessage">The original call message that invoked the method.</param>
 /// <param name="invocationContext">Invocation context dictionary passed into the call.</param>
 public TransparentProxyMethodReturn(Exception ex, IMethodCallMessage callMessage, IDictionary invocationContext)
 {
     this.callMessage = callMessage;
     this.invocationContext = invocationContext;
     this.exception = ex;
     this.arguments = new object[0];
     this.outputs = new ParameterCollection(this.arguments, new ParameterInfo[0], pi => false);
 }
 /// <summary>
 /// Creates a new <see cref="TransparentProxyMethodReturn"/> object that contains a
 /// return value.
 /// </summary>
 /// <param name="callMessage">The original call message that invoked the method.</param>
 /// <param name="returnValue">Return value from the method.</param>
 /// <param name="arguments">Collections of arguments passed to the method (including the new
 /// values of any out params).</param>
 /// <param name="invocationContext">Invocation context dictionary passed into the call.</param>
 public TransparentProxyMethodReturn(IMethodCallMessage callMessage, object returnValue, object[] arguments, IDictionary invocationContext)
 {
     this.callMessage = callMessage;
     this.invocationContext = invocationContext;
     this.arguments = arguments;
     this.returnValue = returnValue;
     this.outputs = new TransparentProxyOutputParameterCollection(callMessage, arguments);
 }
Esempio n. 4
0
        public VirtualMethodReturn(IMethodInvocation originalInvocation, Exception exception)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(originalInvocation, "originalInvocation");

            invocationContext = originalInvocation.InvocationContext;
            this.exception = exception;
            outputs = new ParameterCollection(new object[0], new ParameterInfo[0], delegate { return false; });
        }
Esempio n. 5
0
        public VirtualMethodReturn(IMethodInvocation originalInvocation, object returnValue, object[] arguments)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(originalInvocation, "originalInvocation");

            invocationContext = originalInvocation.InvocationContext;
            this.returnValue = returnValue;
            outputs = new ParameterCollection(arguments, originalInvocation.MethodBase.GetParameters(),
                delegate(ParameterInfo pi) { return pi.ParameterType.IsByRef; });
        }
 /// <summary>
 /// Creates a new <see cref="IMethodInvocation"/> implementation that wraps
 /// the given <paramref name="callMessage"/>, with the given ultimate
 /// target object.
 /// </summary>
 /// <param name="callMessage">Remoting call message object.</param>
 /// <param name="target">Ultimate target of the method call.</param>
 public TransparentProxyMethodInvocation(IMethodCallMessage callMessage, object target)
 {
     this.callMessage = callMessage;
     this.invocationContext = new Hashtable();
     this.target = target;
     this.arguments = callMessage.Args;
     this.inputParams = new TransparentProxyInputParameterCollection(callMessage, this.arguments);
     this.allParams =
         new ParameterCollection(arguments, callMessage.MethodBase.GetParameters(), info => true);
 }
        /// <summary>
        /// Construct a new <see cref="VirtualMethodInvocation"/> instance for the
        /// given target object and method, passing the <paramref name="parameterValues"/>
        /// to the target method.
        /// </summary>
        /// <param name="target">Object that is target of this invocation.</param>
        /// <param name="targetMethod">Method on <paramref name="target"/> to call.</param>
        /// <param name="parameterValues">Values for the parameters.</param>
        public VirtualMethodInvocation(object target, MethodBase targetMethod, params object[] parameterValues)
        {
            this.target = target;
            this.targetMethod = targetMethod;
            this.context = new Hashtable();

            ParameterInfo[] targetParameters = targetMethod.GetParameters();
            this.arguments = new ParameterCollection(parameterValues, targetParameters, param => true );
            this.inputs = new ParameterCollection(parameterValues, targetParameters, param => !param.IsOut);
        }
Esempio n. 8
0
        public VirtualMethodInvocation(object target, MethodBase targetMethod, params object[] parameterValues)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(targetMethod, "targetMethod");

            this.target = target;
            this.targetMethod = targetMethod;
            this.context = new Dictionary<string, object>();

            ParameterInfo[] targetParameters = targetMethod.GetParameters();
            this.arguments = new ParameterCollection(parameterValues, targetParameters, param => true);
            this.inputs = new ParameterCollection(parameterValues, targetParameters, param => !param.IsOut);
        }
Esempio n. 9
0
        public static IMethodInvocation GetNullValueProxyMock(int count)
        {
            var stub = new MethodInvocationStubProxy();
            var method = typeof(MethodInvocationStubProxy).GetMethod("StubMethod");
            var parms = new ParameterCollection(new object[] { null, count }, method.GetParameters(), p => true);

            var mi = new Mock<IMethodInvocation>();
            mi.Setup(x => x.MethodBase).Returns(method);
            mi.Setup(x => x.Target).Returns(stub);
            mi.Setup(x => x.Inputs).Returns(parms);
            return mi.Object;
        }
        public TransparentProxyMethodInvocation(IMethodCallMessage callMessage, object target)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(callMessage, "callMessage");

            this.callMessage = callMessage;
            this.invocationContext = new Dictionary<string, object>();
            this.target = target;
            this.arguments = callMessage.Args;
            this.inputParams = new TransparentProxyInputParameterCollection(callMessage, this.arguments);
            this.allParams =
                new ParameterCollection(arguments, callMessage.MethodBase.GetParameters(), info => true);
        }
        public static IMethodInvocation GetMock(StubRequest req = null, int? count = null)
        {
            var stub = new CustomKeyPrefixMethodInvocationStub();
            var method = typeof(CustomKeyPrefixMethodInvocationStub).GetMethod("StubMethod");
            if (req == null)
            {
                req = StubRequest.GetRequest();
            }
            if (count == null)
            {
                count = _random.Next();
            }
            var parms = new ParameterCollection(new object[] { req, count }, method.GetParameters(), p => true);

            var mi = new Mock<IMethodInvocation>();
            mi.Setup(x => x.MethodBase).Returns(method);
            mi.Setup(x => x.Target).Returns(stub);
            mi.Setup(x => x.Inputs).Returns(parms);
            return mi.Object;
        }
 /// <summary>
 /// Construct a <see cref="VirtualMethodReturn"/> instance for when the target method throws an exception.
 /// </summary>
 /// <param name="originalInvocation">The method invocation.</param>
 /// <param name="exception">Exception that was thrown.</param>
 public VirtualMethodReturn(IMethodInvocation originalInvocation, Exception exception)
 {
     invocationContext = originalInvocation.InvocationContext;
     this.exception = exception;
     outputs = new ParameterCollection(new object[0], new ParameterInfo[0], delegate { return false; });
 }