title: Why is the ?? operator not working in Moq setup method
body: <p>Could someone explain to me, why this doesn't work?</p>
  
  <hr>
  
  <pre><code>builder.Setup(b =&gt; b.BuildCommand(query ?? It.IsAny&lt;string&gt;())).Returns(command);
  </code></pre>
  
  <p>If <code>query</code> is <code>null</code>, <code>BuildCommand</code> will be passed <code>null</code>, and not <code>It.IsAny&lt;string&gt;()</code></p>
  
  <p>Instead, I have to do this:</p>
  
  <pre><code>if(query == null)
      builder.Setup(b =&gt; b.BuildCommand(It.IsAny&lt;string&gt;())).Returns(command);
  else
      builder.Setup(b =&gt; b.BuildCommand(query)).Returns(command);
  </code></pre>
  
  <hr>
  
  <p>Is it related to the delegate?</p>
  
  <hr>
  
  <p>EDIT - Complete example</p>
  
  <pre><code>public static void ReturnFromBuildCommand(this Mock&lt;IQueryCommandBuilder&gt; builder, IQueryCommand command, string query = null)
  {
      if(query == null)
          builder.Setup(b =&gt; b.BuildCommand(It.IsAny&lt;string&gt;())).Returns(command);
      else
          builder.Setup(b =&gt; b.BuildCommand(query)).Returns(command);
  }
  </code></pre>
  
  <p>Then I can call it like </p>
  
  <pre><code>var command = new Mock&lt;IQueryCommand&gt;();
  var builder = new Mock&lt;IQueryCommandBuilder&gt;();
  builder.ReturnFromBuildCommand(command.Object);
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>string query = "SELECT Name FROM Persons;";
  builder.ReturnFromBuildCommand(command.Object, query);
  </code></pre>
  
  <p>Depending on whether I care about the parameter or not.</p>