Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何模拟第三方web服务LINQ数据提供商?_C#_Linq_Mocking - Fatal编程技术网

C# 如何模拟第三方web服务LINQ数据提供商?

C# 如何模拟第三方web服务LINQ数据提供商?,c#,linq,mocking,C#,Linq,Mocking,模仿由第三方制作的LINQWeb服务数据提供商,实际上对我来说是一个黑盒子,这涉及到什么?下面是黑盒子的典型用法:(修改以保护无辜者,又名NDA) 到目前为止,我知道结果是IEnumerable。 另一个使用示例: string something="xxx"; var result = from row in conn.SubscribeAsync() where row.this == something select new MyObject(something) { ro

模仿由第三方制作的LINQWeb服务数据提供商,实际上对我来说是一个黑盒子,这涉及到什么?下面是黑盒子的典型用法:(修改以保护无辜者,又名NDA)

到目前为止,我知道
结果
IEnumerable
。 另一个使用示例:

string something="xxx";
var result = from row in conn.SubscribeAsync()
    where row.this == something
    select new MyObject(something) { row.that, row.theOther };
(这将持续推送数据,可能每秒推送几项,我希望模拟仔细计时的序列。)

我想我真正的问题是,它是否会像以下那样简单:

 class MockRemoteServer
 {
     IEnumerable GetSomeData()
     {
          return new[]
          {
              new {this="1",that="2",theOther="special"},
              new {this="hello",that="world",theOther="something"}
          }
     }
 }
或者我需要自己实现一个完整的LINQ数据提供程序吗?
如果有,有关于这方面的书籍或文章建议吗?(我的LINQ知识目前是基于对Jon Skeet的C#Depth的逐页阅读,而不是其他很多…

a
List
通常就足够了(因为它实现了IEnumerable)。但是,如果您想知道查询的实际性能,没有什么比使用实际的RemoteServer更好。

您所做的将基于您实际希望确保其正常工作的内容。我不能100%确定“完全打开”LINQ数据提供程序是什么意思。@Ramhound我也不能确定“完全打开”是什么意思!《c#Depth》这本书没有展示如何编写LINQ数据提供程序,但顺便提到它们并非微不足道。一个特别的问题是我是否需要编写代码来处理Where子句。(我不这么认为:如果我的模拟版本只是返回一大块数据,那么linqto对象应该使用其内置的
Where
函数来过滤它?)
 class MockRemoteServer
 {
     IEnumerable GetSomeData()
     {
          return new[]
          {
              new {this="1",that="2",theOther="special"},
              new {this="hello",that="world",theOther="something"}
          }
     }
 }