title: Mocking generic methods in Moq without specifying T
body: <p>I have an interface with a method as follows: </p>
  
  <pre><code>public interface IRepo
  {
      IA&lt;T&gt; Reserve&lt;T&gt;();
  }
  </code></pre>
  
  <p>I would like to mock the class that contains this method without having to specify Setup methods for every type it could be used for. Ideally, I'd just like it to return a <code>new mock&lt;T&gt;.Object</code>.</p>
  
  <p>How do I achieve this?</p>
  
  <p>It seems my explanation was unclear. Here's an example - this is possible right now, when I specify the T (here, string):</p>
  
  <pre><code>[TestMethod]
  public void ExampleTest()
  {
      var mock = new Mock&lt;IRepo&gt;();
      mock.Setup(pa =&gt; pa.Reserve&lt;string&gt;()).Returns(new Mock&lt;IA&lt;string&gt;&gt;().Object);
  }
  </code></pre>
  
  <p>What I would like to achieve is something like this:</p>
  
  <pre><code>[TestMethod]
  public void ExampleTest()
  {
      var mock = new Mock&lt;IRepo&gt;();
      mock.Setup(pa =&gt; pa.Reserve&lt;T&gt;()).Returns(new Mock&lt;IA&lt;T&gt;&gt;().Object);
      // of course T doesn't exist here. But I would like to specify all types
      // without having to repeat the .Setup(...) line for each of them.
  }
  </code></pre>
  
  <p>Some methods of the object under test might call reserve for three or four different types. If I have to setup all the types I have to write a lot of setup code for every test. But in a single test, I am not concerned with all of them, I simply need non-null mocked objects except for the one that I am actually testing (and for which I gladly write a more complex setup).</p>