< Summary

Class:Azure.Messaging.ServiceBus.Management.QueueRuntimePropertiesExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\QueueRuntimePropertiesExtensions.cs
Covered lines:0
Uncovered lines:52
Coverable lines:52
Total lines:124
Line coverage:0% (0 of 52)
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\Azure.Messaging.ServiceBus\src\Management\QueueRuntimePropertiesExtensions.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 QueueRuntimePropertiesExtensions
 12    {
 13        public static QueueRuntimeProperties ParseFromContent(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(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("Queue was not found", ServiceBusFailureReason.MessagingEntityNotFound);
 032        }
 33
 34        private static QueueRuntimeProperties ParseFromEntryElement(XElement xEntry)
 35        {
 036            var name = xEntry.Element(XName.Get("title", ManagementClientConstants.AtomNamespace)).Value;
 037            var qRuntime = new QueueRuntimeProperties(name);
 38
 039            var qdXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 040                .Element(XName.Get("QueueDescription", ManagementClientConstants.ServiceBusNamespace));
 41
 042            if (qdXml == null)
 43            {
 044                throw new ServiceBusException("Queue was not found", ServiceBusFailureReason.MessagingEntityNotFound);
 45            }
 46
 047            foreach (var element in qdXml.Elements())
 48            {
 049                switch (element.Name.LocalName)
 50                {
 51                    case "AccessedAt":
 052                        qRuntime.AccessedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 053                        break;
 54                    case "CreatedAt":
 055                        qRuntime.CreatedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 056                        break;
 57                    case "MessageCount":
 058                        qRuntime.TotalMessageCount = long.Parse(element.Value, CultureInfo.InvariantCulture);
 059                        break;
 60                    case "SizeInBytes":
 061                        qRuntime.SizeInBytes = long.Parse(element.Value, CultureInfo.InvariantCulture);
 062                        break;
 63                    case "UpdatedAt":
 064                        qRuntime.UpdatedAt = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 065                        break;
 66                    case "CountDetails":
 067                        foreach (var countElement in element.Elements())
 68                        {
 069                            switch (countElement.Name.LocalName)
 70                            {
 71                                case "ActiveMessageCount":
 072                                    qRuntime.ActiveMessageCount = long.Parse(countElement.Value, CultureInfo.InvariantCu
 073                                    break;
 74                                case "DeadLetterMessageCount":
 075                                    qRuntime.DeadLetterMessageCount = long.Parse(countElement.Value, CultureInfo.Invaria
 076                                    break;
 77                                case "ScheduledMessageCount":
 078                                    qRuntime.ScheduledMessageCount = long.Parse(countElement.Value, CultureInfo.Invarian
 079                                    break;
 80                                case "TransferMessageCount":
 081                                    qRuntime.TransferMessageCount = long.Parse(countElement.Value, CultureInfo.Invariant
 082                                    break;
 83                                case "TransferDeadLetterMessageCount":
 084                                    qRuntime.TransferDeadLetterMessageCount = long.Parse(countElement.Value, CultureInfo
 85                                    break;
 86                            }
 87                        }
 88                        break;
 89                }
 90            }
 91
 092            return qRuntime;
 93        }
 94
 95        public static List<QueueRuntimeProperties> 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 queueList = new List<QueueRuntimeProperties>();
 105
 0106                        var entryList = xDoc.Elements(XName.Get("entry", ManagementClientConstants.AtomNamespace));
 0107                        foreach (var entry in entryList)
 108                        {
 0109                            queueList.Add(ParseFromEntryElement(entry));
 110                        }
 111
 0112                        return queueList;
 113                    }
 114                }
 0115            }
 0116            catch (Exception ex) when (!(ex is ServiceBusException))
 117            {
 0118                throw new ServiceBusException(false, ex.Message);
 119            }
 120
 0121            throw new ServiceBusException("No queues were found", ServiceBusFailureReason.MessagingEntityNotFound);
 0122        }
 123    }
 124}