问题描述
我有一些代码可以下载一些 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设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)