title: Changing values of reference parameter within mocked method (Moq)
body: <p>How can I setup Moq to change the values of an inner method parameter, when the parameter is created within another method.  For example (simplified code below):</p>
  
  <pre><code>public class Response
  { 
      public bool Success { get; set; }
      public string[] Messages {get; set;}
  }
  
  public class MyBusinessLogic
  {
      public void Apply(Response response);
  }
  
  
  public class MyService
  {
      private readonly MyBusinessLogic _businessLogic;
  
      ....
  
      public Response Insert()
      {
          var response = new Response();   // Creates the response inside here
          _businessLogic.Apply(response);
  
          if (response.Success) 
          {
              // Do more stuff
          }
      }
  }
  </code></pre>
  
  <p>Let's say I want to unit test the Insert() method.  How can I setup the mock of the Business Logic's Apply() method to receive any Response class and have it populate the returning Response object with Success set to true so that the rest of the code can run.</p>
  
  <p>As an aside, I have changed the return type of the Apply() method to be bool (instead of Void) to have Moq simply return true, similar to below:</p>
  
  <pre><code>mockMyBusinessLogic.Setup(x =&gt; x.Apply(It.IsAny&lt;Response&gt;()).Returns(true);
  </code></pre>
  
  <p>But that feels awkward having a method that does something, and returns something (I prefer having methods just doing one or the other).</p>
  
  <p>Hoping for a way that may look "something" like below (when using void):</p>
  
  <pre><code>mockMyBusinessLogic.Setup(
     x =&gt; x.Apply(It.IsAny&lt;Response&gt;()).Callback(() 
             =&gt; new Response { Success = true });
  </code></pre>