我有一些代码可以下载一些 RSS 源.
I've got some code which downloads some RSS feeds.
我一直在使用 WebClient
或 Argotic.Syndication.RssFeed
库.
I've been using WebClient
or Argotic.Syndication.RssFeed
libraries.
但这些不是可模拟的 :(
我绝对不想每次运行单元测试时都点击真正的 RSS 提要.
I definately do not want to hit the real RSS feed every time I run the unit test.
有人对我能做什么有任何建议吗?
Does anyone have any suggestions to what I can do?
我需要创建一个邪恶的包装器吗?如果是这样.. 对此有何建议?
Do I need to create an evil wrapper? If so .. suggestions on this?
我会为每个外部依赖项创建一个包装器(如果可行的话).因此,与文件系统/网络服务/数据库的每次交互都应仅通过接口完成,这将产生更多可测试的代码.
I go for creating a wrapper for every external dependency (if it's practical). So, every interaction with the filesystem/a webservice/database should be done through an interface only, which will lead to more testable code.
另一个解决方案当然是(一如既往)Typemock Isolator.
Another solution of course is (as always) Typemock Isolator.
这篇关于需要一些建议来尝试模拟 .NET WebClient 或等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!