< Summary

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

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\SubscriptionRuntimeInfoExtensions.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 SubscriptionRuntimeInfoExtensions
 11    {
 12        public static SubscriptionRuntimeInfo ParseFromContent(string topicName, 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(topicName, 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("Subscription was not found");
 031        }
 32
 33        private static SubscriptionRuntimeInfo ParseFromEntryElement(string topicName, XElement xEntry)
 34        {
 035            var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
 036            var subscriptionRuntimeInfo = new SubscriptionRuntimeInfo(topicName, name);
 37
 038            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 039                .Element(XName.Get("SubscriptionDescription", ManagementClientConstants.ServiceBusNamespace));
 40
 041            if (qdXml == null)
 42            {
 043                throw new MessagingEntityNotFoundException("Subscription was not found");
 44            }
 45
 046            foreach (var element in qdXml.Elements())
 47            {
 048                switch (element.Name.LocalName)
 49                {
 50                    case "AccessedAt":
 051                        subscriptionRuntimeInfo.AccessedAt = DateTime.Parse(element.Value);
 052                        break;
 53                    case "CreatedAt":
 054                        subscriptionRuntimeInfo.CreatedAt = DateTime.Parse(element.Value);
 055                        break;
 56                    case "UpdatedAt":
 057                        subscriptionRuntimeInfo.UpdatedAt = DateTime.Parse(element.Value);
 058                        break;
 59                    case "MessageCount":
 060                        subscriptionRuntimeInfo.MessageCount = long.Parse(element.Value);
 061                        break;
 62                    case "CountDetails":
 063                        subscriptionRuntimeInfo.MessageCountDetails = new MessageCountDetails();
 064                        foreach (var countElement in element.Elements())
 65                        {
 066                            switch (countElement.Name.LocalName)
 67                            {
 68                                case "ActiveMessageCount":
 069                                    subscriptionRuntimeInfo.MessageCountDetails.ActiveMessageCount = long.Parse(countEle
 070                                    break;
 71                                case "DeadLetterMessageCount":
 072                                    subscriptionRuntimeInfo.MessageCountDetails.DeadLetterMessageCount = long.Parse(coun
 073                                    break;
 74                                case "ScheduledMessageCount":
 075                                    subscriptionRuntimeInfo.MessageCountDetails.ScheduledMessageCount = long.Parse(count
 076                                    break;
 77                                case "TransferMessageCount":
 078                                    subscriptionRuntimeInfo.MessageCountDetails.TransferMessageCount = long.Parse(countE
 079                                    break;
 80                                case "TransferDeadLetterMessageCount":
 081                                    subscriptionRuntimeInfo.MessageCountDetails.TransferDeadLetterMessageCount = long.Pa
 82                                    break;
 83                            }
 84                        }
 85                        break;
 86                }
 87            }
 88
 089            return subscriptionRuntimeInfo;
 90        }
 91
 92        public static List<SubscriptionRuntimeInfo> ParseCollectionFromContent(string topicPath, string xml)
 93        {
 94            try
 95            {
 096                var xDoc = XElement.Parse(xml);
 097                if (!xDoc.IsEmpty)
 98                {
 099                    if (xDoc.Name.LocalName == "feed")
 100                    {
 0101                        var subscriptionList = new List<SubscriptionRuntimeInfo>();
 102
 0103                        var entryList = xDoc.Elements(XName.Get("entry", ManagementClientConstants.AtomNamespace));
 0104                        foreach (var entry in entryList)
 105                        {
 0106                            subscriptionList.Add(ParseFromEntryElement(topicPath, entry));
 107                        }
 108
 0109                        return subscriptionList;
 110                    }
 111                }
 0112            }
 0113            catch (Exception ex) when (!(ex is ServiceBusException))
 114            {
 0115                throw new ServiceBusException(false, ex);
 116            }
 117
 0118            throw new MessagingEntityNotFoundException("No subscriptions were found");
 0119        }
 120    }
 121}