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

  • Home
  • SEARCH
  • 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 4097642
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:11:59+00:00 2026-05-20T20:11:59+00:00

Good evening, I am working to get my head around unit testing and I’m

  • 0

Good evening,

I am working to get my head around unit testing and I’m having a little trouble determining how far I can push unit testing before it turns into integration testing.

An example from the project I’m working on now: it has a class that performs LDAP searches against Active Directory using DirectorySearcher and returns the results as Person objects. My first inclination was to grab the interface for DirectorySearcher and then create a fairly sophisticated stub that I can use for testing. However, that proved problematic because DirectorySearcher doesn’t seem to use an interface and it would require a lot of code to stub it out successfully.

My next thought was to create an Searcher class that internally uses DirectorySearcher, which would let me test the mapping between the LDAP results and the Person object mapping, but that doesn’t gain me very much and it’s yet another level of abstraction.

So I guess the bottom line is this: is there a way structure this so I can do most of my work with unit testing? I’d really rather keep the integration test suite as small as possible, since I have to do the testing against an external data source that keeps changing. I suspect there’s a pattern for doing this, but I haven’t been able to find it.

Thanks!

  • 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-05-20T20:12:00+00:00Added an answer on May 20, 2026 at 8:12 pm

    If you have a class that you can’t dependency inject, then the best pattern would be to create a wrapper object and wrap that object. Then, you can inject your wrapper (or mock of the wrapper) to gain that functionality.

    So in your case, you were correct to create a wrapper “Searcher” class that internally calls DirectorySearcher. Whatever methods you need to call on the DirectorySearcher, you provide as virtual methods on your Searcher class. Then you can create a mock searcher class with overriden methods and inject that when unit testing (Or, have Moq create it for you!)

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

Sidebar

Related Questions

Good evening, I'm having trouble with model binding and validation but I don't know
Good evening I've got a little problem with my DataGridView in a .NET Windows
Good evening, I am working on a program where some application config info is
Good evening all, I've been working on an MD5 tool in C# that takes
Good evening :) I'm playing around with g++ and makefiles. I've gotten to this
Good evening everyone! I am working on learning some java and I have made
Good evening, I am having a weird issue with a method I am trying
good evening. ingore all other elements, I want get first image in each foreach.
Good evening, In a test JSF 2.0 web app, I am trying to get
Good morning, afternoon, evening or night (depending on your timezone). This is just a

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.