title: NSubstitute to return a Null for an object
body: <p>I am new to unit testing and it sounds to me like it should be easy to get NSubstitute to be able to return null for a method but I cannot get it to work.</p>
  
  <p>I have tried this for a Get method that should return a Campaign method</p>
  
  <pre><code>_campaigns = Substitute.For&lt;IOptions&lt;Campaigns&gt;&gt;();
  _campaigns.Get(Arg.Any&lt;string&gt;()).Returns(null); 
  </code></pre>
  
  <p>In production I use a FirstOrDefault() method to return the campaign object and it returns null if it does not exist. So in my unit test I want to test that case, but I cannot fake it with NSubstitute as I get the following error when compiling:</p>
  
  <blockquote>
    <p>error CS0121: The call is ambiguous between the following methods or
    properties: 'SubstituteExtensions.Returns(T, T, params T[])' and
    'SubstituteExtensions.Returns(T, Func, params
    Func[])'</p>
  </blockquote>
  
  <p>I do this to avoid the error:</p>
  
  <pre><code>_campaigns.Get(Arg.Any&lt;string&gt;()).Returns((Campaign)null);
  </code></pre>
  
  <p>but then I get an execution error on that line:</p>
  
  <blockquote>
    <p>System.NullReferenceException : Object reference not set to an
    instance of an object.</p>
  </blockquote>