title: How to dispose a mock object?
body: <p>I have a mock object that starts a timer and needs to be disposed of in my test. What is the proper way to dispose the mock object? In my class to be mocked, I have:</p>
  
  <pre><code>protected virtual void Dispose(bool disposing)
  {
      if (!_disposed)
      {
          if (disposing)
          {
              // Stop and dispose timer here.
          }
  
          _disposed = true;
      }
  }
  
  public void Dispose()
  {
      Dispose(true);
  }
  </code></pre>
  
  <p>So now in my test, I need to mock the object, use it, and then make sure it's getting disposed. I know I can just set <code>CallBase = true</code>, but I'm not sure if this is the correct (industry standard) way of doing things:</p>
  
  <pre><code>[TestMethod]
  public void TestSomething()
  {
      var mock = new Mock&lt;ObjectWithTimer&gt;() { CallBase = true };
  
      using (var foo = mock.Object)
      {
          foo.DoSomething(); // This consequently starts a timer.
      } // Here, Dispose() will be called.
  }
  </code></pre>
  
  <p>When the using block ends, <code>Dispose()</code> is called, which calls the base <code>Dispose(bool)</code>. However, is it possible to do this disposing without adding <code>CallBase = true</code> to my mock? This is not ideal when I need mock to override other methods.</p>