< Summary

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

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\SqlFilterExtensions.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 SqlFilterExtensions
 11    {
 12        public static Filter ParseFromXElement(XElement xElement)
 13        {
 014            var expression = xElement.Element(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace))
 015            if (string.IsNullOrWhiteSpace(expression))
 16            {
 017                return null;
 18            }
 19
 020            var filter = new SqlFilter(expression);
 21
 022            var parameters = xElement.Element(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));
 023            if (parameters != null && parameters.HasElements)
 24            {
 025                foreach(var param in parameters.Elements(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.
 26                {
 027                    var key = param.Element(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace))?.Value;
 028                    var value = XmlObjectConvertor.ParseValueObject(param.Element(XName.Get("Value", ManagementClientCon
 029                    filter.Parameters.Add(key, value);
 30                }
 31            }
 32
 033            return filter;
 34        }
 35
 36        public static XElement Serialize(this SqlFilter filter, string filterName)
 37        {
 038            XElement parameterElement = null;
 039            if (filter.parameters != null)
 40            {
 041                parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));
 042                foreach (var param in filter.Parameters)
 43                {
 044                    parameterElement.Add(
 045                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace)
 046                            new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
 047                            XmlObjectConvertor.SerializeObject(param.Value)));
 48                }
 49            }
 50
 051            return new XElement(
 052                XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
 053                new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), filterName),
 054                new XElement(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace), filter.SqlExpres
 055                parameterElement);
 56        }
 57    }
 58}