views:

305

answers:

2

What's the best way to unit test an application accessing the ActiveDirectory and/or mock the dependencies to the AD?

All the required types such as DirectorySearcher and DirectoryEntry don't appear to be easily mockable.

We've got methods like FindByUserName() and would like to (unit) test them.

+6  A: 

If they're not mockable (don't have MSDN at hand, so I can't really tell), you can always abstract them behind an IDirectorySearcher and IDirectoryEntry and mock these. With this approach you can simplify the API by tailoring it specifically to suit your needs.

Anton Gogolev
Thanks for your quick answer. I'll try a few things out and I'll let you know what worked.
kay.herzam
+1  A: 

Is there no other possibility to use a leightweight directory server (ldap) like java developers do with Apache DS (http://directory.apache.org) in .NET?!

This would be a nice alternative.

Was thinking the same thing...
WayneC