< Summary

Class:Microsoft.Azure.ServiceBus.Management.TopicRuntimeInfoExtensions
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Management\TopicRuntimeInfoExtensions.cs
Covered lines:0
Uncovered lines:53
Coverable lines:53
Total lines:124
Line coverage:0% (0 of 53)
Covered branches:0
Total branches:40
Branch coverage:0% (0 of 40)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromContent(...)-0%0%
ParseFromEntryElement(...)-0%0%
ParseCollectionFromContent(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Management\TopicRuntimeInfoExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft. All rights reserved.
 2// Licensed under the MIT license. See LICENSE file in the project root for full license information.
 3
 4namespace Microsoft.Azure.ServiceBus.Management
 5{
 6    using System;
 7    using System.Xml.Linq;
 8    using System.Collections.Generic;
 9
 10    internal static class TopicRuntimeInfoExtensions
 11    {
 12        public static TopicRuntimeInfo ParseFromContent(string xml)
 13        {
 14            try
 15            {
 016                var xDoc = XElement.Parse(xml);
 017                if (!xDoc.IsEmpty)
 18                {
 019                    if (xDoc.Name.LocalName == "entry")
 20                    {
 021                        return ParseFromEntryElement(xDoc);
 22                    }
 23                }
 024            }
 025            catch (Exception ex) when (!(ex is ServiceBusException))
 26            {
 027                throw new ServiceBusException(false, ex);
 28            }
 29
 030            throw new MessagingEntityNotFoundException("Topic was not found");
 031        }
 32
 33        static TopicRuntimeInfo ParseFromEntryElement(XElement xEntry)
 34        {
 035            var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
 036            var topicRuntimeInfo = new TopicRuntimeInfo(name);
 37
 038            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 039                .Element(XName.Get("TopicDescription", ManagementClientConstants.ServiceBusNamespace));
 40
 041            if (qdXml == null)
 42            {
 043                throw new MessagingEntityNotFoundException("Topic was not found");
 44            }
 45
 046            foreach (var element in qdXml.Elements())
 47            {
 048                switch (element.Name.LocalName)
 49                {
 50                    case "AccessedAt":
 051                        topicRuntimeInfo.AccessedAt = DateTime.Parse(element.Value);
 052                        break;
 53                    case "CreatedAt":
 054                        topicRuntimeInfo.CreatedAt = DateTime.Parse(element.Value);
 055                        break;
 56                    case "SizeInBytes":
 057                        topicRuntimeInfo.SizeInBytes = long.Parse(element.Value);
 058                        break;
 59                    case "SubscriptionCount":
 060                        topicRuntimeInfo.SubscriptionCount = int.Parse(element.Value);
 061                        break;
 62                    case "UpdatedAt":
 063                        topicRuntimeInfo.UpdatedAt = DateTime.Parse(element.Value);
 064                        break;
 65                    case "CountDetails":
 066                        topicRuntimeInfo.MessageCountDetails = new MessageCountDetails();
 067                        foreach (var countElement in element.Elements())
 68                        {
 069                            switch (countElement.Name.LocalName)
 70                            {
 71                                case "ActiveMessageCount":
 072                                    topicRuntimeInfo.MessageCountDetails.ActiveMessageCount = long.Parse(countElement.Va
 073                                    break;
 74                                case "DeadLetterMessageCount":
 075                                    topicRuntimeInfo.MessageCountDetails.DeadLetterMessageCount = long.Parse(countElemen
 076                                    break;
 77                                case "ScheduledMessageCount":
 078                                    topicRuntimeInfo.MessageCountDetails.ScheduledMessageCount = long.Parse(countElement
 079                                    break;
 80                                case "TransferMessageCount":
 081                                    topicRuntimeInfo.MessageCountDetails.TransferMessageCount = long.Parse(countElement.
 082                                    break;
 83                                case "TransferDeadLetterMessageCount":
 084                                    topicRuntimeInfo.MessageCountDetails.TransferDeadLetterMessageCount = long.Parse(cou
 85                                    break;
 86                            }
 87                        }
 88                        break;
 89                }
 90            }
 91
 092            return topicRuntimeInfo;
 93        }
 94
 95        public static List<TopicRuntimeInfo> ParseCollectionFromContent(string xml)
 96        {
 97            try
 98            {
 099                var xDoc = XElement.Parse(xml);
 0100                if (!xDoc.IsEmpty)
 101                {
 0102                    if (xDoc.Name.LocalName == "feed")
 103                    {
 0104                        var topicList = new List<TopicRuntimeInfo>();
 105
 0106                        var entryList = xDoc.Elements(XName.Get("entry", ManagementClientConstants.AtomNamespace));
 0107                        foreach (var entry in entryList)
 108                        {
 0109                            topicList.Add(ParseFromEntryElement(entry));
 110                        }
 111
 0112                        return topicList;
 113                    }
 114                }
 0115            }
 0116            catch (Exception ex) when (!(ex is ServiceBusException))
 117            {
 0118                throw new ServiceBusException(false, ex);
 119            }
 120
 0121            throw new MessagingEntityNotFoundException("No topics were found");
 0122        }
 123    }
 124}