gpt4 book ai didi

c# - 在 fluentassertion 上调用异步任务

转载 作者:行者123 更新时间:2023-11-30 19:14:53 25 4
gpt4 key购买 nike

可能是一个简单的,但无法让它工作;

我已将方法上的签名一更改为任务

在我的单元测试中,我使用了流畅的断言。

但无法让它工作:

        _catalogVehicleMapper
.Invoking(m => m.MapToCatalogVehiclesAsync(searchResult, filtersInfo, request, default(CancellationToken)))
.Should().Throw<ArgumentException>()
.WithMessage("One of passed arguments has null value in mapping path and can not be mapped");

MapToCatalogVehiclesAsync 是异步方法,但我需要等待它,但等待和异步调用似乎并没有做到。有人……?

最佳答案

虽然 Fabio 的回答也是正确的,但你也可以这样做:

_catalogVehicleMapper
.Awaiting(m => m.MapToCatalogVehiclesAsync(searchResult, filtersInfo, request, default(CancellationToken)))
.Should().Throw<ArgumentException>()
.WithMessage("One of passed arguments has null value in mapping path and can not be mapped");

作为旁注,我建议始终在 WithMessage 中使用通配符。参见 this blog post 中的第 10 点.

关于c# - 在 fluentassertion 上调用异步任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51661681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com