gpt4 book ai didi

c# - Azure IQueueClient : How do you simulate incoming messages?

转载 作者:行者123 更新时间:2023-12-04 20:19:40 24 4
gpt4 key购买 nike

我正在测试的单元是一个 IHostedService,它使用来自 Microsoft.Azure.ServiceBus 的 IQueueClient 进行通信。据我所知,没有像 .Receive() 这样的函数,这就是我这样做的原因:

_inputQueueClient.Setup(x => x.RegisterMessageHandler(
It.IsAny<Func<Message, CancellationToken, Task>>(),
It.IsAny<MessageHandlerOptions>()))
.Callback<Func<Message, CancellationToken, Task>, MessageHandlerOptions>((x, y) => _messageReceivedHandler = x);

这样我就可以获取消息处理方法并直接在我的单元测试中调用它。这是模拟收到消息的适当方法还是有更好的方法?

最佳答案

按照 gnud 所说:对于一个简单的单元测试,您只需针对消息处理程序方法编写单元测试,Azure 队列客户端本身不会出现在图中。

如果您无法轻松访问该处理程序以进行单元测试(由于其访问级别),那么这通常是一个很好的指标,表明某些内容可以分解为原始类所依赖的单独类。这也有助于您遵守 SRP 👍

关于c# - Azure IQueueClient : How do you simulate incoming messages?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60492718/

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