title: How to modify an invocation parameter of a mocked method with Moq?
body: <p>Is it possible to modify an invocation parameter of a mocked method? In particular I'm looking to change <code>buffer</code> in the following example to a pre-populated byte array.</p>
  
  <p>Example:<br>
  <code>int MockedClass.Read(byte[] buffer, int offset, int count)</code></p>
  
  <p>Explanation:<br>
  Calling <code>Read</code> loads <code>count</code> bytes reading from <code>offset</code> into the supplied byte array <code>buffer</code>.</p>
  
  <p>Now I would like to have buffer populated after the call to <code>Read</code> has been made in my application code. Is that possible?</p>
  
  <p>If yes, how would I go about successive calls to <code>Read</code>? I would like successive calls to return a different buffer each time if possible.</p>
  
  <p>EDIT:</p>
  
  <p>using the <code>Setup</code> command like this:  </p>
  
  <p><code>MockedClass.Setup(x =&gt; x.Read(It.IsAny&lt;byte[]&gt;(), It.IsAny&lt;int&gt;(), It.IsAny&lt;int&gt;()).Callback( (byte[] buffer, int offset, int count) =&gt; buffer[0] = 0xAA);</code></p>
  
  <p>gives me a weird problem when executing the unit test: Once the call to <code>Read</code> is made and the delegate code (<code>buffer[0] = 0xAA</code>) is executed the debugger shows that <code>buffer</code> is actually <code>null</code> and the unit test execution stops after executing this command. Is my syntax borked or is that a bug?</p>