小编Kla*_*sen的帖子

如何使用 Visual Studio 的 Fakes 框架对异步方法进行存根?

我需要存根的方法的调用方式如下:

List<DocumentInfo> documentInfosToDelete = await _documentInfoRepository.GetListByExternalIdAsync(
    partyLegalEntity, 
    externalId,
    type,
    status);
Run Code Online (Sandbox Code Playgroud)

这有效,但会生成编译器警告:“此异步方法缺少‘等待’运算符”等。

   testService.DocumentInfoRepos.GetListByExternalIdAsyncStringStringDocumentTypeDocumentStatus =
                (async (a, b, c, d) => 
            {
                GetListByExternalIdAsyncCalled = true;
                return new List<DocumentInfo>();
            });
Run Code Online (Sandbox Code Playgroud)

我想摆脱这些警告,因为它们会淹没任何有关实际问题的警告。

返回 new Task(...) 挂起。如果我正确理解了我在 WWW 上找到的内容,Task.Run(...) 所做的事情与我们正在使用的等待异步模式完全不同。

该怎么办?

c# mstest stub async-await microsoft-fakes

1
推荐指数
1
解决办法
3148
查看次数

标签 统计

async-await ×1

c# ×1

microsoft-fakes ×1

mstest ×1

stub ×1