title: Strange behavior with NUnit, ExpectedException & yield return
body: <p>I have a strange behavior in a tests where I want to test that an exception is thrown when null is passed in as a parameter. When I run the test I get from NUnit:</p>
  
  <pre><code>    System.ArgumentNullException was expected
      -- Exception doesn't have a stack trace -- 
  </code></pre>
  
  <p>My test:</p>
  
  <pre><code>[Test]
  [ExpectedException(typeof(ArgumentNullException))]
  public void Should_not_retrieve_any_fields_when_file_is_null()
  {
      _creator.CreateFields(null);
  }
  </code></pre>
  
  <p>My implementation:</p>
  
  <pre><code>public IEnumerable&lt;ImportField&gt; CreateFields(HttpPostedFileBase file)
  {
      if (file == null) throw new ArgumentNullException("file");
  
      using (var reader = new StreamReader(file.InputStream))
      {
          var firstLine = reader.ReadLine();
          var columns = firstLine.Split(new[] { ',' });
  
          for (var i = 0; i &lt; columns.Length; i++)
          {
              yield return new ImportField(columns[i], i);
          }
      }
  }
  </code></pre>
  
  <p>Is there a logical explanation to this behavior and should I make my implementation differently?</p>