title: How to spy the class under test with AutofacContrib.NSubstitute
body: <p>I'm running unit tests in a class library project with NSpec framework, AutofacContrib.NSubstitute v3.3.2.0, NSubstitute v1.7.0.0 (the latest as of now is 1.8.2).</p>
  
  <p>The <em>Class Under Test</em> instance is built with <code>AutoSubstitute</code>, in order to automock all its needed dependencies.</p>
  
  <pre><code>AutoSubstitute autoSubstitute = new AutoSubstitute();
  
  MainPanelViewModel viewModel = autoSubstitute.Resolve&lt;MainPanelViewModel&gt;();
  </code></pre>
  
  <p>If working properly, my Class Under Test at some point will invoke one of it's base class methods with some specific input parameter (the base class is out of my control):</p>
  
  <pre><code>// ...
  base.ActivateItem(nextScreen);
  // ...
  </code></pre>
  
  <p>So, for test expectation, I need to check (spy) that the instance invokes the base method:</p>
  
  <pre><code>viewModel.Received().ActivateItem(Arg.Any&lt;SomeSpecificScreenType&gt;());
  </code></pre>
  
  <p>Here's the problem: when I try to do this, at runtime NSubstitute complains that I can only ran <code>Received()</code> against an object created with <code>Substitute.For&lt;&gt;()</code>. I also checked quickly AutofacContrib.NSubstitute source code, but I could not find a way to obtain the instance with automocking and at the same time <em>wrap</em> it somehow in a spy object or something like that.</p>
  
  <p>I also thought that maybe <code>Substitute.ForPartsOf&lt;&gt;()</code> could be helpful, but that method does not seem to be found in NSubstitute v1.7.0.</p>
  
  <p>For sake of completeness, here's NSubstitute full error:</p>
  
  <blockquote>
    <p>NSubstitute extension methods like .Received() can only be called on objects created using Substitute.For() and related methods.</p>
  </blockquote>