title: Moq expectations on the same method call with different arguments
body: <p>I am trying to set up a mock object in a loop that will return different values for a function call with different arguments:</p>
  
  <pre><code>var myMock= new Mock&lt;IInterface&gt;();
  for (int i = 0; i &lt; fromKeys.Count; ++i)
  {
      var value= new[] {new[] {1.0 + i}};
      _values.Add(value);
      myMock.Setup(x =&gt; x.Provide(fromKeys[i])).Returns(new Sth(fromKeys[i], value));
  }
  _myObject = myMock.Object;
  </code></pre>
  
  <p>but it crashes when I am calling <code>Provide</code> with the first key in the production code (and not during test setup):</p>
  
  <pre><code>System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
    ----&gt; System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.
  Parameter name: index
     at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, ref SignatureStruct sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
     at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
     at System.Delegate.DynamicInvokeImpl(Object[] args)
     at Moq.Evaluator.SubtreeEvaluator.Evaluate(Expression e)
     at Moq.Matchers.LazyEvalMatcher.Matches(Object value)
     at Moq.MethodCall.Matches(ICallContext call)
     at System.Linq.Enumerable.LastOrDefault(IEnumerable`1 source, Func`2 predicate)
     at Moq.ExtractProxyCall.HandleIntercept(ICallContext invocation, InterceptStrategyContext ctx)
     at Moq.Interceptor.Intercept(ICallContext invocation)
     at Castle.DynamicProxy.AbstractInvocation.Proceed()
     at Castle.Proxies.IBrownianProviderProxy.Provide(BrowniansKey keys)
     at MyCode.....
  </code></pre>
  
  <p>How can I set it up?</p>