title: Verifying if a void method has been called using Moq
body: <p>I have a class which is responsible for building PPT slides for exporting. To unit test this I have created an interface so it can be mocking using Moq; all great so far. However I run into difficulties when trying to test that my method has been called. It is a void method so at this point I only want to know that the method has been hit.</p>
  
  <p>Here is my interface:</p>
  
  <pre><code>interface IPowerpointExporter
  {
      void AddSlides(int amount);
  
      void setTitle(string title);
  }
  </code></pre>
  
  <p>And here's my unit test:</p>
  
  <pre><code>[TestMethod]
  public void testPPTObject()
  {
      var mockPPT = new Mock&lt;IPowerpointExporter&gt;();
      mockPPT.Setup(m =&gt; m.AddSlides(1)).Verifiable();
      mockPPT.Object.AddSlides(1);
      mockPPT.VerifyAll();
  }
  </code></pre>
  
  <p>However when I come to call <code>AddSlides()</code> I get a <code>GeneratorException</code>. The explanation for this is that my IPowerpointExporter was not accessible. I have a feeling this is because I am trying to call a method on an interface, though I'm unsure since I've got my object at <code>mockPPT.Object.AddSlides();</code> at this point. </p>
  
  <p>Note that I've also tried the following trying to use an actual object rather than Interface.Object. This also gives the same exception:</p>
  
  <pre><code>[TestMethod]
  public void testPPTObject()
  {
      var mockPPT = new Mock&lt;IPowerpointExporter&gt;();
      mockPPT.Setup(m =&gt; m.AddSlides(1)).Verifiable();
  
      ExportPowerPoint temp = (ExportPowerPoint)mockPPT.Object;
      temp.AddSlides(1);
      mockPPT.VerifyAll();
  }
  </code></pre>
  
  <p>Using Moq how can I check that my method has been called? Is what I'm doing above along the right lines?</p>