title: How to unit test Dispose() using reflection?
body: <p>I want to write unit tests for a class that implements IDisposable.  The class has numerous private fields that also implement IDisposable.  In my test, I want to verify that when I call <code>Dispose()</code>, it correctly calls <code>Dispose()</code> on all of its IDisposable fields.  Essentially, I want my unit test to look like this:</p>
  
  <pre><code>var o = new ObjectUnderTest();
  o.Dispose();
  Assert.IsFalse(ObjectHasUndisposedDisposables(o));
  </code></pre>
  
  <p>I was thinking of using reflection to achieve this.  It seems like this would be a fairly common requirement, but I can't find any examples of it.</p>
  
  <p>Anyone tried this?</p>
  
  <p>EDIT -- I do NOT want to have to inject the Disposables into the class under test.</p>