public void AddInvocationExecutor(IInvocation invocation, INMockitoSmartParameter[] smartParameters, IInvocationExecutor executor) { var method = invocation.Method; var genericArguments = invocation.GenericArguments; var methodParameters = method.GetParameters(); var invocationArguments = invocation.Arguments; // Flatten params[] of invocation arguments if (methodParameters.Length > 0 && methodParameters.Last().GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0 && invocationArguments.Last() != null) { var paramsArray = (Array)invocationArguments.Last(); var newInvocationArguments = new object[invocationArguments.Length + paramsArray.Length - 1]; var cutIndex = invocationArguments.Length - 1; Array.Copy(invocationArguments, newInvocationArguments, cutIndex); Array.Copy(paramsArray, 0, newInvocationArguments, cutIndex, paramsArray.Length); invocationArguments = newInvocationArguments; } // Convert all invocation arguments into eq(arg[i]) smart parameters if (smartParameters.Length == 0) { smartParameters = ConvertInvocationArgumentsToEqualityParameters(invocationArguments); } // Find out/ref parameters, swap them with null and record the index => smart parameter replacement. var refReplacementsByIndex = new List <KeyValuePair <int, object> >(); for (var i = 0; i < methodParameters.Length; i++) { var parameter = methodParameters[i]; if (parameter.Attributes.HasFlag(ParameterAttributes.Out)) { var replacement = invocation.Arguments[i]; smartParameters[i] = null; refReplacementsByIndex.Add(new KeyValuePair <int, object>(i, replacement)); } } var tracker = trackerByArguments.FirstOrDefault(kvp => kvp.Key.Item1 == method && kvp.Key.Item2 == genericArguments && SmartParametersEqual(kvp.Key.Item3, smartParameters)).Value; if (tracker == null) { tracker = new InvocationResultTracker(GetDefaultValue(method.ReturnType), refReplacementsByIndex); var key = new Tuple <MethodInfo, Type[], INMockitoSmartParameter[]>(method, genericArguments, smartParameters); trackerByArguments.Add(new KeyValuePair <Tuple <MethodInfo, Type[], INMockitoSmartParameter[]>, InvocationResultTracker>(key, tracker)); } tracker.AddResult(executor); }
public StateChangeDefinitionActions(IIdentityResolver idResolver, IInvocationExecutor invocationExec) { _idResolver = idResolver; _invocationExec = invocationExec; }
public ActionActions(IIdentityResolver idResolver, IInvocationExecutor invocationExec) { _idResolver = idResolver; _invocationExec = invocationExec; }
public override void SetUp() { base.SetUp(); executor = scope.Resolve<IInvocationExecutor>(); }
public override void SetUp() { base.SetUp(); executor = scope.Resolve<IInvocationExecutor>(); InvocationExecutorTestsMockImplementor.WasCalled = false; }
public ParameterizedActionDefinitionActions(IIdentityResolver idResolver, IInvocationExecutor invocationExec) { }
public void AddResult(IInvocationExecutor executor) { results.Add(executor); }