title: Mocking Generic Method with NSubstitute
body: <p>I have an interface with a number of generic methods. These methods perform operations based on the type of data that is passed in. How do I mock this with NSubstitute? At the moment, I had to resort to using a concrete class instead of a mock since I cannot handle all possible types that the method will be called with. </p>
  
  <pre><code>public interface IInstanceSource
  {
      bool CanCreate&lt;T&gt;();
      T Create&lt;T&gt;();
      void Register&lt;T&gt;(Func&lt;T&gt; creator);
  }
  
      public static IInstanceSource GetInstanceSource()
      {
          var _data = new Dictionary&lt;Type, Func&lt;object&gt;&gt;();
          var a = Substitute.For&lt;IInstanceSource&gt;();
          //code below fails since T is not defined. How do I make the code below accept any type?
          a.WhenForAnyArgs(x=&gt;x.Register(Arg.Any&lt;Func&lt;T&gt;&gt;)).Do(x=&gt; { /* todo */});
          a.CanCreate&lt;T&gt;().Returns(x =&gt; _data[typeof (T)]);
          return a;
      }
  </code></pre>
  
  <p>thanks.</p>