问题描述
什么是单元的最佳方式测试应用程序访问ActiveDirectory中和/或嘲笑的依赖关系到AD?
What's the best way to unit test an application accessing the ActiveDirectory and/or mock the dependencies to the AD?
所有必需的类型,如 DirectorySearcher从
和的DirectoryEntry
似乎不容易mockable。
All the required types such as DirectorySearcher
and DirectoryEntry
don't appear to be easily mockable.
我们已经有了像 FindByUserName方法()
,并想(单位)进行测试。
We've got methods like FindByUserName()
and would like to (unit) test them.
推荐答案
如果他们不mockable(没有MSDN的手,所以我真的不能告诉),可以随时提取其背后的 IDirectorySearcher
和 IDirectoryEntry
和模拟这些。通过这种方法,你可以通过调整它专门满足您的需求简化了API。
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.
这篇关于单元测试code访问的ActiveDirectory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!