private IList <SbTopic> BuildTopicList(ISbManager SbManager, string TopicName) { IList <SbTopic> result = new List <SbTopic>(); IList <TopicDescription> topics = new List <TopicDescription>(); if (TopicName != null) { topics.Add(SbManager.GetTopicByName(TopicName)); } else { topics = SbManager.GetAllTopics(); } foreach (var topic in topics) { IList <SubscriptionDescription> subscriptions = SbManager.GetAllSubscriptions(topic.Path); TopicRuntimeInfo topicRuntimeInfo = SbManager.GetTopicRuntimeInfo(topic.Path); result.Add(new SbTopic { TopicName = topic.Path, Subscriptions = subscriptions.Select(sub => sub.SubscriptionName).ToList(), ScheduledMessages = topicRuntimeInfo.MessageCountDetails.ScheduledMessageCount }); } return(result); }
public async Task GetTopicRuntimeInfo() { var topicName = nameof(GetTopicRuntimeInfo).ToLower() + Guid.NewGuid().ToString("D").Substring(0, 8); var subscriptionName = Guid.NewGuid().ToString("D").Substring(0, 8); var client = new ServiceBusManagementClient(TestEnvironment.ServiceBusConnectionString); TopicDescription topicDescription = await client.CreateTopicAsync(topicName); // Changing Last Updated Time topicDescription.AutoDeleteOnIdle = TimeSpan.FromMinutes(100); await client.UpdateTopicAsync(topicDescription); await client.CreateSubscriptionAsync(topicName, subscriptionName); List <TopicRuntimeInfo> runtimeInfoList = new List <TopicRuntimeInfo>(); await foreach (TopicRuntimeInfo topicRuntimeInfo in client.GetTopicsRuntimeInfoAsync()) { runtimeInfoList.Add(topicRuntimeInfo); } runtimeInfoList = runtimeInfoList.Where(e => e.Name.StartsWith(nameof(GetTopicRuntimeInfo).ToLower())).ToList(); Assert.True(runtimeInfoList.Count == 1, $"Expected 1 topic but {runtimeInfoList.Count} topics returned"); TopicRuntimeInfo runtimeInfo = runtimeInfoList.First(); Assert.NotNull(runtimeInfo); Assert.AreEqual(topicName, runtimeInfo.Name); Assert.True(runtimeInfo.CreatedAt < runtimeInfo.UpdatedAt); Assert.True(runtimeInfo.UpdatedAt < runtimeInfo.AccessedAt); Assert.AreEqual(1, runtimeInfo.SubscriptionCount); TopicRuntimeInfo singleTopicRI = await client.GetTopicRuntimeInfoAsync(runtimeInfo.Name); Assert.AreEqual(runtimeInfo.AccessedAt, singleTopicRI.AccessedAt); Assert.AreEqual(runtimeInfo.CreatedAt, singleTopicRI.CreatedAt); Assert.AreEqual(runtimeInfo.UpdatedAt, singleTopicRI.UpdatedAt); Assert.AreEqual(runtimeInfo.SizeInBytes, singleTopicRI.SizeInBytes); Assert.AreEqual(runtimeInfo.SubscriptionCount, singleTopicRI.SubscriptionCount); await client.DeleteTopicAsync(topicName); }