public async Task BrokerRouterUsesFactoryToAddNewBrokers() { var router = new BrokerRouter(new KafkaOptions { KafkaServerUri = new List <Uri> { new Uri("http://localhost:1") }, KafkaConnectionFactory = _mockKafkaConnectionFactory.Object }); _mockKafkaConnection1.Setup(x => x.SendAsync(It.IsAny <IKafkaRequest <MetadataResponse> >())) .Returns(() => Task.Run(async() => new List <MetadataResponse> { await BrokerRouterProxy.CreateMetadataResponseWithMultipleBrokers() })); await router.RefreshMissingTopicMetadata(TestTopic); var topics = router.GetTopicMetadataFromLocalCache(TestTopic); _mockKafkaConnectionFactory.Verify(x => x.Create(It.Is <KafkaEndpoint>(e => e.Endpoint.Port == 2), It.IsAny <TimeSpan>(), It.IsAny <IKafkaLog>(), It.IsAny <int>(), It.IsAny <TimeSpan?>(), It.IsAny <StatisticsTrackerOptions>()), Times.Once()); }