public static void AddTopicClients(this IServiceCollection services, string serviceBusConnectionString, string topicNames) { var topics = topicNames.Split(','); var pcsBusSender = new PcsBusSender(); foreach (var topicName in topics) { if (!string.IsNullOrWhiteSpace(topicName)) { var topicClient = new TopicClient(serviceBusConnectionString, topicName); pcsBusSender.Add(topicName, topicClient); } } services.AddSingleton <IPcsBusSender>(pcsBusSender); }
public void Setup() { var topicClients = new PcsBusSender(); _topicClientMock1 = new Mock <ITopicClient>(); _topicClientMock2 = new Mock <ITopicClient>(); _topicClientMock3 = new Mock <ITopicClient>(); _topicClientMock4 = new Mock <ITopicClient>(); _topicClientMock4.Setup(t => t.SendAsync(It.IsAny <Message>())) .Callback <Message>(m => _messageBodyOnTopicClient4 = Encoding.UTF8.GetString(m.Body)); topicClients.Add("topic1", _topicClientMock1.Object); topicClients.Add("topic2", _topicClientMock2.Object); topicClients.Add("topic3", _topicClientMock3.Object); topicClients.Add("topic4", _topicClientMock4.Object); _busEvents = new List <BusEvent> { new BusEvent { Created = DateTime.Now.AddMinutes(-10), Event = "topic2", Sent = Status.UnProcessed, Id = 1, Message = "{\"Plant\":\"NGPCS_TEST_BROWN\",\"ProjectName\":\"Message 10 minutes ago not sent\"}" }, new BusEvent { Created = DateTime.Now.AddMinutes(-10), Event = "topic3", Sent = Status.UnProcessed, Id = 1, Message = "{\"Plant\" : \"PCS$HF_LNG\", \"Responsible\" : \"8460-E015\", \"Description\" : \" Installere bonding til JBer ved V8 område\"}" } }; _busEventRepository = new Mock <IBusEventRepository>(); _iUnitOfWork = new Mock <IUnitOfWork>(); _busEventRepository.Setup(b => b.GetEarliestUnProcessedEventChunk()).Returns(() => Task.FromResult(_busEvents)); _dut = new BusSenderService(topicClients, _busEventRepository.Object, _iUnitOfWork.Object, new Mock <ILogger <BusSenderService> >().Object, new Mock <ITelemetryClient>().Object); }