简体   繁体   English

访问ActiveDirectory的代码的单元测试

[英]Unit tests for code accessing ActiveDirectory

What's the best way to unit test an application accessing the ActiveDirectory and/or mock the dependencies to the AD? 对访问ActiveDirectory和/或模拟AD依赖项的应用程序进行单元测试的最佳方法是什么?

All the required types such as DirectorySearcher and DirectoryEntry don't appear to be easily mockable. 所有必需的类型(如DirectorySearcherDirectoryEntry似乎都不容易模拟。

We've got methods like FindByUserName() and would like to (unit) test them. 我们有像FindByUserName()这样的方法,并希望(单元)测试它们。

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. 如果它们不可模糊(手头没有MSDN,所以我无法确定),你总是可以在IDirectorySearcherIDirectoryEntry后面抽象它们并模拟它们。 With this approach you can simplify the API by tailoring it specifically to suit your needs. 通过这种方法,您可以通过专门定制API来简化API,以满足您的需求。

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?! 没有其他可能使用像java开发人员那样在.NET中使用Apache DS( http://directory.apache.org )的轻量级目录服务器(ldap)吗?

This would be a nice alternative. 这将是一个不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM