Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:21:05+00:00 2026-06-11T05:21:05+00:00

I have a third party component that I am trying to write unit tests

  • 0

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.

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:

  • The class has two constructors (one takes a parameter)
  • The class inherits from IDisposable

My questions are:

  1. Does my implementation below look right?
  2. Did I handle the IDisposable implementation correctly in the proxy class?
  3. 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.

The meta data looks like (slimmed down version):

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<string> Capability();
    public void Connect(string host);
    protected override void GetServerGreeting();
}

Based on the meta data, my interface looks like (after removing methods/properties/access modifiers that are invalid in an interface definition):

public interface IPopClient : IDisposable
{
    bool HasTimeStamp { get; }
    List<string> Capability();
    void Connect(string host);
    void ConnectSSL(string host);
}

Based on the interface, I then created the wrapper class:

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<string> Capability()
        return pop3.Capability();

    public void Connect(string host)
        pop3.Connect(host);

    public void Dispose()
    {
        if (pop3 != null)
            pop3.Dispose();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:21:07+00:00Added an answer on June 11, 2026 at 5:21 am

    Your proxy looks fine. Based on it, it should be very easy to mock the relevant parts of the interface your tests are dealing with.

    About the IDisposable implementation, take a look at the disposable pattern common practices. This question is about it.

    And for the constructor(s), I’d say that they simply aren’t part of the interface and, as such, don’t need to be replicated in implementations of the proxy. If that leads to strange constructor logic in your DI container, try separating construction from initialization and include the latter in the interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a third party component written in C/C++ (on VS 2010) which can
I have a third party COM component (they don't offer a .Net assy), that
IE7/Windows XP I have a third party component in my page that does a
I have a problem using a third-party component in Delphi 2006 (also Delphi 7),
We have old .net 1.1 project that is using a third party component. Aparently
I have a third party component that produce serialized xml and stored procedure that
I frequently have svn-based projects that include third-party components such as the TinyMCE (in-browser
I have a third party component I'm using and I'm seeing some issues with
I have third-party C code that writes data to a file. I want to
I have third party sites that link to some images on my site. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.