小编let*_*tbe的帖子

检查对于异步方法的Received()调用

当我运行以下代码时:

[Test]
public async Task Can_Test_Update()
{
    var response = await _controller.UpdateAsync(Guid.NewGuid());
    response.Valid.Should().BeTrue();

    _commands.Received().UpdateAsync(
        Arg.Is<Something>(
            l => l.Status == Status.Updated)); 
}
Run Code Online (Sandbox Code Playgroud)

如果我在" await"之前添加" " _commands.Received().UpdateAsync,它会抛出一个空引用异常.我怎样才能阻止这种情况发生,或者await不是必要的?

c# asynchronous nsubstitute async-await

18
推荐指数
4
解决办法
8177
查看次数

标签 统计

async-await ×1

asynchronous ×1

c# ×1

nsubstitute ×1