单元测试code访问的ActiveDirectory [英] Unit tests for code accessing ActiveDirectory

查看:143
本文介绍了单元测试code访问的ActiveDirectory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是单元的最佳方式测试应用程序访问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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆