< Summary

Class:Microsoft.Azure.ServiceBus.CorrelationFilterExtensions
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\CorrelationFilterExtensions.cs
Covered lines:0
Uncovered lines:55
Coverable lines:55
Total lines:99
Line coverage:0% (0 of 55)
Covered branches:0
Total branches:68
Branch coverage:0% (0 of 68)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromXElement(...)-0%0%
Serialize(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Filters\CorrelationFilterExtensions.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
 5{
 6    using System.Xml.Linq;
 7    using Microsoft.Azure.ServiceBus.Filters;
 8    using Microsoft.Azure.ServiceBus.Management;
 9
 10    internal static class CorrelationFilterExtensions
 11    {
 12        public static Filter ParseFromXElement(XElement xElement)
 13        {
 014            var correlationFilter = new CorrelationFilter();
 015            foreach (var element in xElement.Elements())
 16            {
 017                switch (element.Name.LocalName)
 18                {
 19                    case "CorrelationId":
 020                        correlationFilter.CorrelationId = element.Value;
 021                        break;
 22                    case "MessageId":
 023                        correlationFilter.MessageId = element.Value;
 024                        break;
 25                    case "To":
 026                        correlationFilter.To = element.Value;
 027                        break;
 28                    case "ReplyTo":
 029                        correlationFilter.ReplyTo = element.Value;
 030                        break;
 31                    case "Label":
 032                        correlationFilter.Label = element.Value;
 033                        break;
 34                    case "SessionId":
 035                        correlationFilter.SessionId = element.Value;
 036                        break;
 37                    case "ReplyToSessionId":
 038                        correlationFilter.ReplyToSessionId = element.Value;
 039                        break;
 40                    case "ContentType":
 041                        correlationFilter.ContentType = element.Value;
 042                        break;
 43                    case "Properties":
 044                        foreach (var prop in element.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConst
 45                        {
 046                            var key = prop.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Val
 047                            var value = XmlObjectConvertor.ParseValueObject(prop.Element(XName.Get("Value", ManagementCl
 048                            correlationFilter.Properties.Add(key, value);
 49                        }
 50                        break;
 51                    default:
 052                        MessagingEventSource.Log.ManagementSerializationException(
 053                            $"{nameof(CorrelationFilterExtensions)}_{nameof(ParseFromXElement)}",
 054                            element.ToString());
 55                        break;
 56                }
 57            }
 58
 059            return correlationFilter;
 60        }
 61
 62        public static XElement Serialize(this CorrelationFilter filter)
 63        {
 064            XElement parameterElement = null;
 065            if (filter.properties != null)
 66            {
 067                parameterElement = new XElement(XName.Get("Properties", ManagementClientConstants.ServiceBusNamespace));
 068                foreach (var param in filter.properties)
 69                {
 070                    parameterElement.Add(
 071                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)
 072                            new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
 073                            XmlObjectConvertor.SerializeObject(param.Value)));
 74                }
 75            }
 76
 077            return new XElement(
 078                XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
 079                new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), nameof(Correlati
 080                string.IsNullOrWhiteSpace(filter.CorrelationId) ? null :
 081                    new XElement(XName.Get("CorrelationId", ManagementClientConstants.ServiceBusNamespace), filter.Corre
 082                string.IsNullOrWhiteSpace(filter.MessageId) ? null :
 083                    new XElement(XName.Get("MessageId", ManagementClientConstants.ServiceBusNamespace), filter.MessageId
 084                string.IsNullOrWhiteSpace(filter.To) ? null :
 085                    new XElement(XName.Get("To", ManagementClientConstants.ServiceBusNamespace), filter.To),
 086                string.IsNullOrWhiteSpace(filter.ReplyTo) ? null :
 087                    new XElement(XName.Get("ReplyTo", ManagementClientConstants.ServiceBusNamespace), filter.ReplyTo),
 088                string.IsNullOrWhiteSpace(filter.Label) ? null :
 089                    new XElement(XName.Get("Label", ManagementClientConstants.ServiceBusNamespace), filter.Label),
 090                string.IsNullOrWhiteSpace(filter.SessionId) ? null :
 091                    new XElement(XName.Get("SessionId", ManagementClientConstants.ServiceBusNamespace), filter.SessionId
 092                string.IsNullOrWhiteSpace(filter.ReplyToSessionId) ? null :
 093                    new XElement(XName.Get("ReplyToSessionId", ManagementClientConstants.ServiceBusNamespace), filter.Re
 094                string.IsNullOrWhiteSpace(filter.ContentType) ? null :
 095                    new XElement(XName.Get("ContentType", ManagementClientConstants.ServiceBusNamespace), filter.Content
 096                parameterElement);
 97        }
 98    }
 99}