< Summary

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

Metrics

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

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Management\NamespaceInfoExtensions.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
 9    internal class NamespaceInfoExtensions
 10    {
 11        public static NamespaceInfo ParseFromContent(string xml)
 12        {
 13            try
 14            {
 015                var xDoc = XElement.Parse(xml);
 016                if (!xDoc.IsEmpty)
 17                {
 018                    if (xDoc.Name.LocalName == "entry")
 19                    {
 020                        return ParseFromEntryElement(xDoc);
 21                    }
 22                }
 023            }
 024            catch (Exception ex) when (!(ex is ServiceBusException))
 25            {
 026                throw new ServiceBusException(false, ex);
 27            }
 28
 029            throw new ServiceBusException(false, "Unknown error.");
 030        }
 31
 32        private static NamespaceInfo ParseFromEntryElement(XElement xEntry)
 33        {
 034            var nsInfo = new NamespaceInfo();
 35
 036            var nsInfoXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 037                .Element(XName.Get("NamespaceInfo", ManagementClientConstants.ServiceBusNamespace));
 38
 039            if (nsInfoXml == null)
 40            {
 041                throw new ServiceBusException(true);
 42            }
 43
 044            foreach (var element in nsInfoXml.Elements())
 45            {
 046                switch (element.Name.LocalName)
 47                {
 48                    case "CreatedTime":
 049                        nsInfo.CreatedTime = DateTime.Parse(element.Value);
 050                        break;
 51                    case "ModifiedTime":
 052                        nsInfo.ModifiedTime = DateTime.Parse(element.Value);
 053                        break;
 54                    case "Name":
 055                        nsInfo.Name = element.Value;
 056                        break;
 57                    case "Alias":
 058                        nsInfo.Alias = element.Value;
 059                        break;
 60                    case "MessagingUnits":
 061                        int.TryParse(element.Value, out var units);
 062                        nsInfo.MessagingUnits = units;
 063                        break;
 64                    case "NamespaceType":
 065                        if (Enum.TryParse<NamespaceType>(element.Value, out var nsType))
 66                        {
 067                            nsInfo.NamespaceType = nsType;
 68                        }
 069                        else if (element.Value == "Messaging") // TODO: workaround till next major as it's a breaking ch
 70                        {
 071                            nsInfo.NamespaceType = NamespaceType.ServiceBus;
 72                        }
 73                        else
 74                        {
 075                            nsInfo.NamespaceType = NamespaceType.Others;
 76                        }
 077                        break;
 78                    case "MessagingSKU":
 079                        if (Enum.TryParse<MessagingSku>(element.Value, out var nsSku))
 80                        {
 081                            nsInfo.MessagingSku = nsSku;
 82                        }
 83                        else
 84                        {
 085                            nsInfo.MessagingSku = MessagingSku.Others;
 86                        }
 87                        break;
 88                }
 89            }
 90
 091            return nsInfo;
 92        }
 93    }
 94}