title: How to mock IDataReader.GetValues()?
body: <p>I need to mock a call to IDataReader.GetValues(array) using Moq. The GetValues method should populate "array" with the values from the current row in the DataReader and return the data reader field count. </p>
  
  <p>Here is my Mock setup:</p>
  
  <pre><code>var data = new object[] { };
  
  var reader = new Mock&lt;IDataReader&gt;();
  reader.Setup(r =&gt; r.GetValues(data)).Callback&lt;object[]&gt;(d =&gt; {
      Array.Resize(ref d, 2);
      d[0] = "value 1";
      d[1] = "value 2";
  }).Returns(2);
  </code></pre>
  
  <p>... and this is the code being tested ("_reader" is the Mock object):</p>
  
  <pre><code>public int GetValues(object[] values)
  {
      int result = _reader.GetValues(values);
      for (int i = 0; i &lt; values.Length; i++)
      {
          // this is not executed because values.Length == 0
      }
      ...
  </code></pre>
  
  <p>In the code above, result == 2 (ok Mock Setup is working) but "values" never gets populated!</p>
  
  <p>How can I setup the Mock object to populate the "values" array?</p>