< Summary

Class:Azure.Messaging.ServiceBus.Management.TopicRuntimePropertiesExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\TopicRuntimePropertiesExtensions.cs
Covered lines:35
Uncovered lines:9
Coverable lines:44
Total lines:113
Line coverage:79.5% (35 of 44)
Covered branches:26
Total branches:32
Branch coverage:81.2% (26 of 32)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromContent(...)-55.56%50%
ParseFromEntryElement(...)-95.45%90.91%
ParseCollectionFromContent(...)-69.23%66.67%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Xml.Linq;
 6using System.Collections.Generic;
 7using System.Globalization;
 8
 9namespace Azure.Messaging.ServiceBus.Management
 10{
 11    internal static class TopicRuntimePropertiesExtensions
 12    {
 13        public static TopicRuntimeProperties ParseFromContent(string xml)
 14        {
 15            try
 16            {
 417                var xDoc = XElement.Parse(xml);
 418                if (!xDoc.IsEmpty)
 19                {
 420                    if (xDoc.Name.LocalName == "entry")
 21                    {
 422                        return ParseFromEntryElement(xDoc);
 23                    }
 24                }
 025            }
 026            catch (Exception ex) when (!(ex is ServiceBusException))
 27            {
 028                throw new ServiceBusException(false, ex.Message);
 29            }
 30
 031            throw new ServiceBusException("Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound);
 432        }
 33
 34        public static TopicRuntimeProperties ParseFromEntryElement(XElement xEntry)
 35        {
 836            var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
 837            var topicRuntimeInfo = new TopicRuntimeProperties(name);
 38
 839            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 840                .Element(XName.Get("TopicDescription", ManagementClientConstants.ServiceBusNamespace));
 41
 842            if (qdXml == null)
 43            {
 044                throw new ServiceBusException("Topic was not found", ServiceBusFailureReason.MessagingEntityNotFound);
 45            }
 46
 38447            foreach (var element in qdXml.Elements())
 48            {
 18449                switch (element.Name.LocalName)
 50                {
 51                    case "AccessedAt":
 852                        topicRuntimeInfo.AccessedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 853                        break;
 54                    case "CreatedAt":
 855                        topicRuntimeInfo.CreatedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 856                        break;
 57                    case "SizeInBytes":
 858                        topicRuntimeInfo.SizeInBytes = long.Parse(element.Value, CultureInfo.InvariantCulture);
 859                        break;
 60                    case "SubscriptionCount":
 861                        topicRuntimeInfo.SubscriptionCount = int.Parse(element.Value, CultureInfo.InvariantCulture);
 862                        break;
 63                    case "UpdatedAt":
 864                        topicRuntimeInfo.UpdatedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 865                        break;
 66                    case "CountDetails":
 9667                        foreach (var countElement in element.Elements())
 68                        {
 4069                            switch (countElement.Name.LocalName)
 70                            {
 71                                case "ScheduledMessageCount":
 872                                    topicRuntimeInfo.ScheduledMessageCount = long.Parse(countElement.Value, CultureInfo.
 73                                    break;
 74                            }
 75                        }
 76
 77                        break;
 78                }
 79            }
 80
 881            return topicRuntimeInfo;
 82        }
 83
 84        public static List<TopicRuntimeProperties> ParseCollectionFromContent(string xml)
 85        {
 86            try
 87            {
 488                var xDoc = XElement.Parse(xml);
 489                if (!xDoc.IsEmpty)
 90                {
 491                    if (xDoc.Name.LocalName == "feed")
 92                    {
 493                        var topicList = new List<TopicRuntimeProperties>();
 94
 495                        var entryList = xDoc.Elements(XName.Get("entry", ManagementClientConstants.AtomNamespace));
 1696                        foreach (var entry in entryList)
 97                        {
 498                            topicList.Add(ParseFromEntryElement(entry));
 99                        }
 100
 4101                        return topicList;
 102                    }
 103                }
 0104            }
 0105            catch (Exception ex) when (!(ex is ServiceBusException))
 106            {
 0107                throw new ServiceBusException(false, ex.Message);
 108            }
 109
 0110            throw new ServiceBusException("No topics were found", ServiceBusFailureReason.MessagingEntityNotFound);
 4111        }
 112    }
 113}