需要一些建议供试图模拟一个.NET Web客户端或同等学历 [英] Need some advice for trying to mock a .NET WebClient or equivalent
问题描述
我有一些代码,下载一些RSS提要。
I've got some code which downloads some RSS feeds.
我一直在使用 Web客户端
或 Argotic.Syndication.RssFeed
库
但这些都不是mockable:(
我绝对不希望每次运行单元测试时打真正的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?
推荐答案
我去为每一个外部依赖创建一个包装(如果它的实际的)。所以,与文件系统的每一次互动/ web服务/数据库应通过完成唯一接口,这将导致更多的可测试代码。
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隔离。
Another solution of course is (as always) Typemock Isolator.
这篇关于需要一些建议供试图模拟一个.NET Web客户端或同等学历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!