[英]How to mock a 3rd party web service LINQ data provider?
What is involved in mocking a LINQ web service data provider, which is made by a 3rd party, and is effectively a black box to me? 模拟由第三方制作的LINQ Web服务数据提供程序涉及到什么,对我来说实际上是一个黑盒子? Here is typical usage of that black box: (modified to protect the innocent, aka an NDA)
这是黑匣子的典型用法:(修改以保护无辜者,又称NDA)
var conn = new RemoteServer (username,password);
var result = from row in conn.GetSomeData()
where row.this == "Hello" && row.that != "World"
select new { row.this, row.that, row.theOther };
I so far know result
is IEnumerable<T>
. 到目前为止我知道
result
是IEnumerable<T>
。 Another usage example: 另一个用法示例:
string something="xxx";
var result = from row in conn.SubscribeAsync()
where row.this == something
select new MyObject(something) { row.that, row.theOther };
(This will keep pushing data, perhaps a few items each second, and I'll be wanting to mock carefully timed sequences.) (这将继续推送数据,也许每秒推送一些项目,我会想要仔细模拟定时序列。)
I suppose my real question is, will it be as simple as: 我想我真正的问题是,它会如此简单:
class MockRemoteServer
{
IEnumerable GetSomeData()
{
return new[]
{
new {this="1",that="2",theOther="special"},
new {this="hello",that="world",theOther="something"}
}
}
}
Or do I need to implement a full-on LINQ data provider myself? 或者我是否需要自己实现一个完整的LINQ数据提供程序? If so, any book or article recommendations on this?
如果是这样,任何书籍或文章的建议? (My LINQ knowledge is currently based on a cover-to-cover read of Jon Skeet's C# In Depth, and not much else...)
(我的LINQ知识目前基于Jon Skeet的C#In Depth的封面到封面阅读,而不是其他......)
A List<T>
is generally enough (since it implements IEnumerable). List<T>
通常就足够了(因为它实现了IEnumerable)。 However, if you want to know actual performance of your queries, nothing beats using the actual RemoteServer. 但是,如果您想了解查询的实际性能,则无需使用实际的RemoteServer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.