Need some advice for trying to mock a .NET WebClient or equivalent(需要一些建议来尝试模拟 .NET WebClient 或等效项)
问题描述
我有一些代码可以下载一些 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 或等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:需要一些建议来尝试模拟 .NET WebClient 或等效项


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01