I have a linked question here. I read this and I'm trying to mock the dependencies in my Hosted Service. But I'm confused as to assert or verify what. I'm thinking to verify that StartConsumption
on Mock Kafka Topic Consumer Manager
gets invoked. But to set it up, it returns void
. I'm not able to determine how to set up the predicate for the mock.
services.AddSingleton(Mock.Of<IKafkaTopicConsumerManager>(_ =>
_.StartConsumption(
It.IsAny<CancellationToken>(),
It.IsAny<IMessageProcessingCapable>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<List<string>>(),
It.IsAny<string>(),
It.IsAny<int>())==void
));
But at void
it shows up invalid expression term. Below is my Worker.cs which is the Hosted Service
.
protected override async Task ExecuteAsync(CancellationToken cancellationToken)
{
_consumerManager.StartConsumption(
cancellationToken,
_messageProcessor,
_config.GetSection("Kafka:Servers").Get<string>(),
_config.GetSection("ConsumerGroup").Get<string>(),
_config.GetSection("Topics").Get<List<string>>(),
_config.GetSection("Kafka:TopicSuffix").Get<string>(),
_config.GetSection("ConsumerThreads").Get<int>());
}