< Summary

Class:Azure.Messaging.ServiceBus.Management.CorrelationRuleFilterExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\CorrelationRuleFilterExtensions.cs
Covered lines:53
Uncovered lines:3
Coverable lines:56
Total lines:99
Line coverage:94.6% (53 of 56)
Covered branches:52
Total branches:66
Branch coverage:78.7% (52 of 66)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromXElement(...)-88.89%70.83%
Serialize(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.Xml.Linq;
 6using Azure.Messaging.ServiceBus.Diagnostics;
 7
 8namespace Azure.Messaging.ServiceBus.Management
 9{
 10    internal static class CorrelationRuleFilterExtensions
 11    {
 12        public static RuleFilter ParseFromXElement(XElement xElement)
 13        {
 2014            var correlationRuleFilter = new CorrelationRuleFilter();
 33615            foreach (var element in xElement.Elements())
 16            {
 14817                switch (element.Name.LocalName)
 18                {
 19                    case "CorrelationId":
 1620                        correlationRuleFilter.CorrelationId = element.Value;
 1621                        break;
 22                    case "MessageId":
 1623                        correlationRuleFilter.MessageId = element.Value;
 1624                        break;
 25                    case "To":
 1626                        correlationRuleFilter.To = element.Value;
 1627                        break;
 28                    case "ReplyTo":
 1629                        correlationRuleFilter.ReplyTo = element.Value;
 1630                        break;
 31                    case "Label":
 1632                        correlationRuleFilter.Label = element.Value;
 1633                        break;
 34                    case "SessionId":
 1635                        correlationRuleFilter.SessionId = element.Value;
 1636                        break;
 37                    case "ReplyToSessionId":
 1638                        correlationRuleFilter.ReplyToSessionId = element.Value;
 1639                        break;
 40                    case "ContentType":
 1641                        correlationRuleFilter.ContentType = element.Value;
 1642                        break;
 43                    case "Properties":
 9644                        foreach (var prop in element.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConst
 45                        {
 2846                            var key = prop.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Val
 2847                            var value = XmlObjectConvertor.ParseValueObject(prop.Element(XName.Get("Value", ManagementCl
 2848                            correlationRuleFilter.Properties.Add(key, value);
 49                        }
 50                        break;
 51                    default:
 052                        ServiceBusEventSource.Log.ManagementSerializationException(
 053                            $"{nameof(CorrelationRuleFilterExtensions)}_{nameof(ParseFromXElement)}",
 054                            element.ToString());
 55                        break;
 56                }
 57            }
 58
 2059            return correlationRuleFilter;
 60        }
 61
 62        public static XElement Serialize(this CorrelationRuleFilter filter, string filterName)
 63        {
 1264            XElement parameterElement = new XElement(
 1265                XName.Get(
 1266                    "Properties",
 1267                    ManagementClientConstants.ServiceBusNamespace));
 68
 6469            foreach (KeyValuePair<string, object> param in filter.Properties)
 70            {
 2071                parameterElement.Add(
 2072                    new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace),
 2073                        new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
 2074                        XmlObjectConvertor.SerializeObject(param.Value)));
 75            }
 76
 1277            return new XElement(
 1278                XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
 1279                new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), filterName),
 1280                string.IsNullOrWhiteSpace(filter.CorrelationId) ? null :
 1281                    new XElement(XName.Get("CorrelationId", ManagementClientConstants.ServiceBusNamespace), filter.Corre
 1282                string.IsNullOrWhiteSpace(filter.MessageId) ? null :
 1283                    new XElement(XName.Get("MessageId", ManagementClientConstants.ServiceBusNamespace), filter.MessageId
 1284                string.IsNullOrWhiteSpace(filter.To) ? null :
 1285                    new XElement(XName.Get("To", ManagementClientConstants.ServiceBusNamespace), filter.To),
 1286                string.IsNullOrWhiteSpace(filter.ReplyTo) ? null :
 1287                    new XElement(XName.Get("ReplyTo", ManagementClientConstants.ServiceBusNamespace), filter.ReplyTo),
 1288                string.IsNullOrWhiteSpace(filter.Label) ? null :
 1289                    new XElement(XName.Get("Label", ManagementClientConstants.ServiceBusNamespace), filter.Label),
 1290                string.IsNullOrWhiteSpace(filter.SessionId) ? null :
 1291                    new XElement(XName.Get("SessionId", ManagementClientConstants.ServiceBusNamespace), filter.SessionId
 1292                string.IsNullOrWhiteSpace(filter.ReplyToSessionId) ? null :
 1293                    new XElement(XName.Get("ReplyToSessionId", ManagementClientConstants.ServiceBusNamespace), filter.Re
 1294                string.IsNullOrWhiteSpace(filter.ContentType) ? null :
 1295                    new XElement(XName.Get("ContentType", ManagementClientConstants.ServiceBusNamespace), filter.Content
 1296                parameterElement);
 97        }
 98    }
 99}