欧克:操纵传递的参数不起作用
我有这样的东西:
MyMock
.Setup(m => m.MyMethodAsync(It.IsAny<Stream>()))
.Returns((Stream outStream) =>
{
outStream = new MemoryStream(Encoding.UTF8.GetBytes("this is the content"));
return Task.CompletedTask;
});
可以编译和执行。我可以看到运行代码的调试器。但是该方法的来电者无法获得流的值。我想念什么?
EDIT1:
更改返回到回调的行为相同
.Callback((MT365ReceiveResult result, Stream outStream) =>
{
outStream = new MemoryStream(Encoding.UTF8.GetBytes("this is the content"));
});
I have something like this:
MyMock
.Setup(m => m.MyMethodAsync(It.IsAny<Stream>()))
.Returns((Stream outStream) =>
{
outStream = new MemoryStream(Encoding.UTF8.GetBytes("this is the content"));
return Task.CompletedTask;
});
this can be compiled and executed. I can see the debugger running the code. But the caller of this method do not get the value of the Stream. What do i miss?
Edit1:
Change Returns to Callback has the same behavior
.Callback((MT365ReceiveResult result, Stream outStream) =>
{
outStream = new MemoryStream(Encoding.UTF8.GetBytes("this is the content"));
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
示例的代码不使用该方法呼叫者提供的
流
,而是将新的MemoryStream
分配给参数。由于参数未用ref
或 out 标记,因此此重新分配仅在方法中有效,但在外部不有效。我想,您想为呼叫者提供的
流
写一个值。您可以使用以下代码执行此操作:The code of the sample does not use the
Stream
that is provided by the caller of the method, but assigns a newMemoryStream
to the parameter. As the parameter is not marked withref
orout
, this reassignment is only valid in the method, but not outside.I suppose, you want to write a value to the
Stream
that is provided by the caller. You can do this with the following code: