简体   繁体   English

如何模拟第三方Web服务LINQ数据提供程序?

[英]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> . 到目前为止我知道resultIEnumerable<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.

相关问题 错误捕获来自(第三方)Web服务的响应信息 - Capture response information from (3rd party) web service on error 如何避免使用第三方网络服务重复代码-不使用动态代码? - How to avoid code repetition using a 3rd party web service - without using dynamic? 如何使用.NET解析此第三方JSON服务? - How to parse this 3rd party JSON service using .NET? 如何在Azure云服务上使用第三方DLL - How to use 3rd party DLL on Azure Cloud Service 单页应用程序访问公共Web服务:客户端应该直接访问第三方服务器还是通过自己的服务器访问数据? - Single Page Application accessing public web service: should the client go direct to 3rd party server for data, or via own server? 第三方Web服务的WCF包装器-抛弃[OperationContract(IsOneWay = true)] - WCF wrapper for 3rd party web service - fire and forget [OperationContract(IsOneWay = true)] 模拟从第三方类触发事件 - Mock firing an event from 3rd party class 如何禁用第三方事件循环 - How to disable 3rd party event loop 如何序列化第三方课程? - How to serialize 3rd party class? 如何创建一个程序来动态添加/删除可以访问 3rd 方服务端口的 IP? - How can I create a program to dynamically add/remove IP that can access a port to a 3rd party service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM