Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/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# 带有AutoMoq的AutoFixture在自定义后始终返回相同的实例_C#_Moq_Autofixture_Automoq - Fatal编程技术网

C# 带有AutoMoq的AutoFixture在自定义后始终返回相同的实例

C# 带有AutoMoq的AutoFixture在自定义后始终返回相同的实例,c#,moq,autofixture,automoq,C#,Moq,Autofixture,Automoq,我有以下代码来设置来自模拟客户机的一些响应(对于brewity,代码的某些部分被省略): 不幸的是,关于这个话题的报告“相当”空洞 每次调用时,我应该更改什么以获取新实例 //... .Returns(GetNewResponse()); 将返回调用GetNewResponse()时提供的相同实例 如果每次调用都需要不同的实例,则重构。返回以调用委托 //... .Returns(() => GetNewResponse()); //<-- note the function in

我有以下代码来设置来自模拟客户机的一些响应(对于brewity,代码的某些部分被省略):

不幸的是,关于这个话题的报告“相当”空洞

每次调用时,我应该更改什么以获取新实例

//...
.Returns(GetNewResponse());
将返回调用
GetNewResponse()
时提供的相同实例

如果每次调用都需要不同的实例,则重构
。返回
以调用委托

//...
.Returns(() => GetNewResponse()); //<-- note the function in .Returns
/。。。

.Returns(()=>GetNewResponse())//谢谢,这是必要的一步。
//...
.Returns(GetNewResponse());
//...
.Returns(() => GetNewResponse()); //<-- note the function in .Returns