< Summary

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

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\FilterExtensions.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;
 7    using System.Xml.Linq;
 8    using Microsoft.Azure.ServiceBus.Management;
 9
 10    internal static class FilterExtensions
 11    {
 12        public static Filter ParseFromXElement(XElement xElement)
 13        {
 014            var attribute = xElement.Attribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace));
 015            if (attribute == null)
 16            {
 017                return null;
 18            }
 19
 020            switch (attribute.Value)
 21            {
 22                case "SqlFilter":
 023                    return SqlFilterExtensions.ParseFromXElement(xElement);
 24                case "CorrelationFilter":
 025                    return CorrelationFilterExtensions.ParseFromXElement(xElement);
 26                case "TrueFilter":
 027                    return new TrueFilter();
 28                case "FalseFilter":
 029                    return new FalseFilter();
 30                default:
 031                    MessagingEventSource.Log.ManagementSerializationException(
 032                        $"{nameof(FilterExtensions)}_{nameof(ParseFromXElement)}",
 033                        xElement.ToString());
 034                    return null;
 35            }
 36        }
 37
 38        public static XElement Serialize(this Filter filter)
 39        {
 40            switch (filter)
 41            {
 42                case SqlFilter sqlFilter:
 43                    switch (sqlFilter)
 44                    {
 45                        case TrueFilter _:
 046                            return sqlFilter.Serialize(nameof(TrueFilter));
 47
 48                        case FalseFilter _:
 049                            return sqlFilter.Serialize(nameof(FalseFilter));
 50
 51                        default:
 052                            return sqlFilter.Serialize(nameof(SqlFilter));
 53                    }
 54
 55                case CorrelationFilter correlationFilter:
 056                    return correlationFilter.Serialize();
 57
 58                default:
 059                    throw new NotImplementedException($"filter type {filter.GetType().Name} is not supported.");
 60            }
 61        }
 62    }
 63}