Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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# 模拟采用默认为null的可选参数的方法_C#_.net_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Moq_Nest - Fatal编程技术网 elasticsearch,moq,nest,C#,.net,elasticsearch,Moq,Nest" /> elasticsearch,moq,nest,C#,.net,elasticsearch,Moq,Nest" />

C# 模拟采用默认为null的可选参数的方法

C# 模拟采用默认为null的可选参数的方法,c#,.net,elasticsearch,moq,nest,C#,.net,elasticsearch,Moq,Nest,我正在编写一个针对一个函数的单元测试,该函数通过NEST命中Elasticsearch。我的单元测试设置如下所示: var mockResponse = new Mock<IBulkResponse>(); var mockClient = new Mock<IElasticClient>(); mockClient.Setup(x => x.IndexManyAsync<Store>(It.IsAny<IEnumerable<Store&g

我正在编写一个针对一个函数的单元测试,该函数通过NEST命中Elasticsearch。我的单元测试设置如下所示:

var mockResponse = new Mock<IBulkResponse>();
var mockClient = new Mock<IElasticClient>();
mockClient.Setup(x => x.IndexManyAsync<Store>(It.IsAny<IEnumerable<Store>>(), It.IsAny<string>(), It.IsAny<string>())).Returns(Task<IBulkResponse>.Run(() => mockResponse.Object));

我不清楚这里发生了什么。为什么我无法模拟这个采用可选参数的方法?

看来,indexmanyanc的这个特殊重载:

公共静态任务IndexManySync(此IElasticClient客户端,
IEnumerable对象,
字符串索引=null,
字符串类型=null),其中T:class
{
// 
}

公共静态任务IndexManySync(此IElasticClient客户端,
IEnumerable对象,
字符串索引=null,
字符串类型=null),其中T:class
{
// 
}

.

IndexManySync是一种扩展方法吗?IndexManySync是一种扩展方法吗?
An exception of type 'System.NotSupportedException' occurred in Moq.dll but was not handled in user code

Additional information: Expression references a method that does not belong to the mocked object: x => x.IndexManyAsync<Store>(It.IsAny<IEnumerable`1>(), It.IsAny<String>(), It.IsAny<String>())
public static Task<IBulkResponse> IndexManyAsync<T>(this IElasticClient client, 
                                                    IEnumerable<T> objects, 
                                                    string index = null, 
                                                    string type = null) where T : class
{
    // <snip>
}