title: Asserting an exception thrown from a mock object constructor
body: <p>Assume: VS2010, .NET 4, C#, NUnit, Moq</p>
  
  <p>I am new to TDD and came across this issue while working through a project.</p>
  
  <p>Given the class:</p>
  
  <pre><code>public abstract class MyFileType
  {                
      public MyFileType(String fullPathToFile)
      {
          if (!File.Exists(fullPathToFile))
          {
              throw new FileNotFoundException();
          }
  
          // method continues
  
      }
  }
  </code></pre>
  
  <p>I am trying to test it using the method:</p>
  
  <pre><code>[Test]
  [ExpectedException(typeof(System.IO.FileNotFoundException))]
  public void MyFileType_CreationWithNonexistingPath_ExceptionThrown()
  {
      String nonexistingPath = "C:\\does\\not\\exist\\file.ext";
      var mock = new Mock&lt;MyFileType&gt;(nonexistingPath);
  }
  </code></pre>
  
  <p>The test fails and NUnit reports an exception was never thrown. </p>
  
  <p>I did find a <a href="http://nunit.org/index.php?p=exceptionAsserts&amp;r=2.5.9" rel="noreferrer">section in the NUnit docs</a> talking about asserting with exceptions, but the examples didn't seem like what I am trying to do. I am still getting started with NUnit and Moq so I may be going about this the wrong way.</p>
  
  <p>UPDATE:</p>
  
  <p>To help clarify why this example uses an abstract class, it is the base class of a series file types where only the loading and disposing of the data would differ between subclassed types. My initial thought was to put the logic for open/setup into a base class since it is the same for all types.</p>