< Summary

Class:Azure.Messaging.ServiceBus.Management.NamespacePropertiesExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\NamespacePropertiesExtensions.cs
Covered lines:24
Uncovered lines:7
Coverable lines:31
Total lines:77
Line coverage:77.4% (24 of 31)
Covered branches:35
Total branches:42
Branch coverage:83.3% (35 of 42)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromContent(...)-55.56%50%
ParseFromEntryElement(...)-86.36%86.84%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Globalization;
 6using System.Xml.Linq;
 7
 8namespace Azure.Messaging.ServiceBus.Management
 9{
 10    internal class NamespacePropertiesExtensions
 11    {
 12        public static NamespaceProperties ParseFromContent(string xml)
 13        {
 14            try
 15            {
 416                var xDoc = XElement.Parse(xml);
 417                if (!xDoc.IsEmpty)
 18                {
 419                    if (xDoc.Name.LocalName == "entry")
 20                    {
 421                        return ParseFromEntryElement(xDoc);
 22                    }
 23                }
 024            }
 025            catch (Exception ex) when (!(ex is ServiceBusException))
 26            {
 027                throw new ServiceBusException(false, ex.Message);
 28            }
 29
 030            throw new ServiceBusException(false, "Unknown error.");
 431        }
 32
 33        private static NamespaceProperties ParseFromEntryElement(XElement xEntry)
 34        {
 435            var nsInfo = new NamespaceProperties();
 36
 437            var nsInfoXml = xEntry.Element(XName.Get("content", ManagementClientConstants.AtomNamespace))?
 438                .Element(XName.Get("NamespaceInfo", ManagementClientConstants.ServiceBusNamespace));
 39
 440            if (nsInfoXml == null)
 41            {
 042                throw new ServiceBusException(true, "Unknown error.");
 43            }
 44
 5645            foreach (var element in nsInfoXml.Elements())
 46            {
 2447                switch (element.Name.LocalName)
 48                {
 49                    case "CreatedTime":
 450                        nsInfo.CreatedTime = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 451                        break;
 52                    case "ModifiedTime":
 453                        nsInfo.ModifiedTime = DateTimeOffset.Parse(element.Value, CultureInfo.InvariantCulture);
 454                        break;
 55                    case "Name":
 456                        nsInfo.Name = element.Value;
 457                        break;
 58                    case "Alias":
 059                        nsInfo.Alias = element.Value;
 060                        break;
 61                    case "MessagingUnits":
 462                        _ = int.TryParse(element.Value, out var units);
 463                        nsInfo.MessagingUnits = units;
 464                        break;
 65                    case "NamespaceType":
 466                            nsInfo.NamespaceType = element.Value;
 467                        break;
 68                    case "MessagingSKU":
 469                            nsInfo.MessagingSku = element.Value;
 70                        break;
 71                }
 72            }
 73
 474            return nsInfo;
 75        }
 76    }
 77}