title: Moq and constructors - testing initialisation behaviour
body: <p>I'd like to be able to test a class initialises correctly using Moq:</p>
  <pre><code>class ClassToTest
  {
      public ClassToTest()
      {
          Method1(@&quot;C:\myfile.dat&quot;)
      }
   
      public virtual void Method1(string filename)
      {
          // mock this method
          File.Create(filename);
      }
  }
  </code></pre>
  <p>I thought I'd be able to use the <code>CallBase</code> property to create a testable version of the class, then use <code>.Setup()</code> to ensure <code>Method1()</code> does not execute any code.</p>
  <p>However, creating the <code>Mock&lt;ClassToTest&gt;()</code> doesn't call the constructor, and if it did it'd be too late to do the <code>Setup()</code>!</p>
  <p>If this is impossible, what is the best way round the problem whilst ensuring that the constructor behaves correctly?</p>
  <p><strong>EDIT:</strong> To make it clearer, I've added a parameter to <code>Method1()</code> to take a filename and added some behaviour. The test I'd like to write would be a working version of the following:</p>
  <pre><code>[Test]
  public void ClassToTest_ShouldCreateFileOnInitialisation()
  {
      var mockClass = new Mock&lt;ClassToTest&gt;() { CallBase = true };
      mockClass.Setup(x =&gt; x.Method1(It.IsAny&lt;string&gt;());
  
      mockClass.Verify(x =&gt; x.Method1(@&quot;C:\myfile.dat&quot;));
  }
  </code></pre>