< Summary

Class:Azure.Messaging.ServiceBus.Management.SubscriptionRuntimePropertiesExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\SubscriptionRuntimePropertiesExtensions.cs
Covered lines:0
Uncovered lines:48
Coverable lines:48
Total lines:118
Line coverage:0% (0 of 48)
Covered branches:0
Total branches:36
Branch coverage:0% (0 of 36)

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\Azure.Messaging.ServiceBus\src\Management\SubscriptionRuntimePropertiesExtensions.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 SubscriptionRuntimePropertiesExtensions
 12    {
 13        public static SubscriptionRuntimeProperties ParseFromContent(string topicName, string xml)
 14        {
 15            try
 16            {
 017                var xDoc = XElement.Parse(xml);
 018                if (!xDoc.IsEmpty)
 19                {
 020                    if (xDoc.Name.LocalName == "entry")
 21                    {
 022                        return ParseFromEntryElement(topicName, 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("Subscription was not found", ServiceBusFailureReason.MessagingEntityNotFound)
 032        }
 33
 34        private static SubscriptionRuntimeProperties ParseFromEntryElement(string topicName, XElement xEntry)
 35        {
 036            var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
 037            var subscriptionRuntimeInfo = new SubscriptionRuntimeProperties(topicName, name);
 38
 039            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 040                .Element(XName.Get("SubscriptionDescription", ManagementClientConstants.ServiceBusNamespace));
 41
 042            if (qdXml == null)
 43            {
 044                throw new ServiceBusException("Subscription was not found", ServiceBusFailureReason.MessagingEntityNotFo
 45            }
 46
 047            foreach (var element in qdXml.Elements())
 48            {
 049                switch (element.Name.LocalName)
 50                {
 51                    case "AccessedAt":
 052                        subscriptionRuntimeInfo.AccessedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCu
 053                        break;
 54                    case "CreatedAt":
 055                        subscriptionRuntimeInfo.CreatedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCul
 056                        break;
 57                    case "UpdatedAt":
 058                        subscriptionRuntimeInfo.UpdatedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCul
 059                        break;
 60                    case "MessageCount":
 061                        subscriptionRuntimeInfo.TotalMessageCount = long.Parse(element.Value, CultureInfo.InvariantCultu
 062                        break;
 63                    case "CountDetails":
 064                        foreach (var countElement in element.Elements())
 65                        {
 066                            switch (countElement.Name.LocalName)
 67                            {
 68                                case "ActiveMessageCount":
 069                                    subscriptionRuntimeInfo.ActiveMessageCount = long.Parse(countElement.Value, CultureI
 070                                    break;
 71                                case "DeadLetterMessageCount":
 072                                    subscriptionRuntimeInfo.DeadLetterMessageCount = long.Parse(countElement.Value, Cult
 073                                    break;
 74                                case "TransferMessageCount":
 075                                    subscriptionRuntimeInfo.TransferMessageCount = long.Parse(countElement.Value, Cultur
 076                                    break;
 77                                case "TransferDeadLetterMessageCount":
 078                                    subscriptionRuntimeInfo.TransferDeadLetterMessageCount = long.Parse(countElement.Val
 79                                    break;
 80                            }
 81                        }
 82                        break;
 83                }
 84            }
 85
 086            return subscriptionRuntimeInfo;
 87        }
 88
 89        public static List<SubscriptionRuntimeProperties> ParseCollectionFromContent(string topicPath, string xml)
 90        {
 91            try
 92            {
 093                var xDoc = XElement.Parse(xml);
 094                if (!xDoc.IsEmpty)
 95                {
 096                    if (xDoc.Name.LocalName == "feed")
 97                    {
 098                        var subscriptionList = new List<SubscriptionRuntimeProperties>();
 99
 0100                        var entryList = xDoc.Elements(XName.Get("entry", ManagementClientConstants.AtomNamespace));
 0101                        foreach (var entry in entryList)
 102                        {
 0103                            subscriptionList.Add(ParseFromEntryElement(topicPath, entry));
 104                        }
 105
 0106                        return subscriptionList;
 107                    }
 108                }
 0109            }
 0110            catch (Exception ex) when (!(ex is ServiceBusException))
 111            {
 0112                throw new ServiceBusException(false, ex.Message);
 113            }
 114
 0115            throw new ServiceBusException("No subscriptions were found", ServiceBusFailureReason.MessagingEntityNotFound
 0116        }
 117    }
 118}