title: What is the difference between passing It.IsAny<int>() and the value of It.IsAny<int>() to a method setup
body: <p>I'm using Moq and want to create builder classes to create my mocks with preset reasonable defaults that can be overridden during test setup as needed. The approach I took uses extension methods in which I pass input parameter values and expected output. In doing so, I'm seeing different behavior in what seems to me to be semantically equivalent code: passing It.IsAny() directly in a setup vs passing the value of It.IsAny() indirectly in a setup. Example:</p>
  
  <pre><code>public interface IFoo
  {
      bool Bar(int value);
      bool Bar2(int value);
  }
  public class Foo : IFoo
  {
      public bool Bar(int value) { return false; }
      public bool Bar2(int value) { return false; }
  }
  
  var mock = new Mock&lt;IFoo&gt;();
  mock.Setup(x =&gt; x.Bar(It.IsAny&lt;int&gt;())).Returns(true);
  Assert.IsTrue(mock.Object.Bar(123));                    // Succeeds
  
  var myValue = It.IsAny&lt;int&gt;();
  mock.Setup(x =&gt; x.Bar2(myValue)).Returns(true);
  Assert.IsTrue(mock.Object.Bar2(123));                   // Fails
  </code></pre>
  
  <p>Both calls are equivalent (to me), yet the call to Bar2 fails assertion. Why is this?</p>