title: Moq a base class function from a derived class
body: <p>I am new to Moq and I just watched the pluralsight video on Moqing so I felt empowered to go and write some tests. I have a Base Class let’s say Sheet which implements an interface ISheet.  Sheet is the base class for pages: </p>
  
  <pre><code>abstract class Sheet: ISheet
  {
      public virtual void CreateSheet()  // Defined in ISheet
      {
      }
      public virtual void BuildSheet() // Defined in ISheet
      {
      }
      //and some abstract methods, etc.
  }
  
  public class Page : Sheet
  {
      public override void CreateSheet()
      {
          BuildSheet(); // Base class implementation
      }
  }
  </code></pre>
  
  <p>I overrode one of the methods from the base class which is <code>CreateSheet()</code>, but I want to test that the <code>BuildSheet()</code> method in the base class  is called from my derived class:</p>
  
  <p>So in my Test Class, I Moq the SUT instead of the interface</p>
  
  <pre><code>var MockSheet = new Moq&lt;Page&gt;();
  </code></pre>
  
  <p>call the method:</p>
  
  <pre><code>var actual = MockSheet.Object.CreateSheet(); 
  </code></pre>
  
  <p>Then verify</p>
  
  <pre><code>MockSheet.Verify(x =&gt; x.BuildSheet(), Times.AtLeastOnce);
  </code></pre>
  
  <p>Instead I get MockException “Expected Invocation on the mock at least once but was never performed.   The CreateSheet method never gets called.  If I change he CreateSheet method to:</p>
  
  <pre><code>public void CreateDocSheet() // removed override
  {
      BuildSheet() // base classses implementation
  }
  </code></pre>
  
  <p>And in the test call:</p>
  
  <pre><code>var actual = MockSheet.Object.CreateDocSheet();  
  </code></pre>
  
  <p>It works. I don’t understand why. I believe that functionally that this is a valid way of coding, I have sheet, that has 2 pages, I have an Interface that defines all the functions and properties that should be implemented, I implement these functions in the base class, but not all methods need to implemented in the derived classes so, some method are overridden and some use the base class implementation.  Please explain why it is an issue to use the overridden version of the function?</p>