< Summary

Class:Azure.Messaging.ServiceBus.Management.SqlRuleFilterExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\SqlRuleFilterExtensions.cs
Covered lines:23
Uncovered lines:1
Coverable lines:24
Total lines:55
Line coverage:95.8% (23 of 24)
Covered branches:13
Total branches:16
Branch coverage:81.2% (13 of 16)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromXElement(...)-90.91%75%
Serialize(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Xml.Linq;
 5
 6namespace Azure.Messaging.ServiceBus.Management
 7{
 8    internal static class SqlRuleFilterExtensions
 9    {
 10        internal static RuleFilter ParseFromXElement(XElement xElement)
 11        {
 1612            var expression = xElement.Element(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace))
 1613            if (string.IsNullOrWhiteSpace(expression))
 14            {
 015                return null;
 16            }
 17
 1618            var filter = new SqlRuleFilter(expression);
 19
 1620            var parameters = xElement.Element(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));
 1621            if (parameters != null && parameters.HasElements)
 22            {
 20023                foreach (var param in parameters.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants
 24                {
 8425                    var key = param.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value;
 8426                    var value = XmlObjectConvertor.ParseValueObject(param.Element(XName.Get("Value", ManagementClientCon
 8427                    filter.Parameters.Add(key, value);
 28                }
 29            }
 1630            return filter;
 31        }
 32
 33        public static XElement Serialize(this SqlRuleFilter filter, string filterName)
 34        {
 3635            XElement parameterElement = null;
 3636            if (filter.Parameters != null)
 37            {
 3638                parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));
 16039                foreach (var param in filter.Parameters)
 40                {
 4441                    parameterElement.Add(
 4442                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)
 4443                            new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
 4444                            XmlObjectConvertor.SerializeObject(param.Value)));
 45                }
 46            }
 47
 3648            return new XElement(
 3649                XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
 3650                new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), filterName),
 3651                new XElement(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace), filter.SqlExpres
 3652                parameterElement);
 53        }
 54    }
 55}