title: Creating a wrapper class to use for mocking that uses IDisposable
body: <p>I have a third party component that I am trying to write unit tests around. The problem is that I can't mock the object and there is no interface. </p>
  
  <p>I decided to create an interface and a wrapper class calling into the code for the sake of mocking. I looked into the class definition that is generated by Visual Studio using the meta data and noticed a few things:</p>
  
  <ul>
  <li>The class has two constructors (one takes a parameter)</li>
  <li>The class inherits from IDisposable</li>
  </ul>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Does my implementation below look right?</li>
  <li>Did I handle the IDisposable implementation correctly in the proxy class?</li>
  <li>Do I need the second constructor in the proxy class since the interface does not support constructor definitions? I use dependency injection in my code and I assume unless I tell my DI framework to use the second constructor I don't really need it but I am not sure.</li>
  </ol>
  
  <p>The meta data looks like (slimmed down version):</p>
  
  <pre><code>public class PopClient : IDisposable
  {
      public const int DefaultPort = 110;
      public const int DefaultSSLPort = 995;
  
      public PopClient();
      public PopClient(AddressFamily addressFamily);
      public bool HasTimeStamp { get; }
      public List&lt;string&gt; Capability();
      public void Connect(string host);
      protected override void GetServerGreeting();
  }
  </code></pre>
  
  <p>Based on the meta data, my interface looks like (after removing methods/properties/access modifiers that are invalid in an interface definition):</p>
  
  <pre><code>public interface IPopClient : IDisposable
  {
      bool HasTimeStamp { get; }
      List&lt;string&gt; Capability();
      void Connect(string host);
      void ConnectSSL(string host);
  }
  </code></pre>
  
  <p>Based on the interface, I then created the wrapper class:</p>
  
  <pre><code>public class PopClientProxy : IPopClient
  {
      private readonly Pop3 pop3;
  
      public PopClientProxy()
          this.pop3 = new Pop3();
  
      public PopClientProxy(AddressFamily addressFamily)
          this.pop3 = new Pop3(addressFamily);
  
      public bool HasTimeStamp
          get { return pop3.HasTimeStamp; }
  
      public List&lt;string&gt; Capability()
          return pop3.Capability();
  
      public void Connect(string host)
          pop3.Connect(host);
  
      public void Dispose()
      {
          if (pop3 != null)
              pop3.Dispose();
      }
  }
  </code></pre>