< Summary

Class:Azure.Messaging.ServiceBus.Management.RuleFilterExtensions
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\Rules\RuleFilterExtensions.cs
Covered lines:9
Uncovered lines:8
Coverable lines:17
Total lines:63
Line coverage:52.9% (9 of 17)
Covered branches:12
Total branches:18
Branch coverage:66.6% (12 of 18)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ParseFromXElement(...)-50%60%
Serialize(...)-60%75%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Xml.Linq;
 6using Azure.Messaging.ServiceBus.Diagnostics;
 7
 8namespace Azure.Messaging.ServiceBus.Management
 9{
 10    internal static class RuleFilterExtensions
 11    {
 12        public static RuleFilter ParseFromXElement(XElement xElement)
 13        {
 4814            var attribute = xElement.Attribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace));
 4815            if (attribute == null)
 16            {
 017                return null;
 18            }
 19
 4820            switch (attribute.Value)
 21            {
 22                case "SqlFilter":
 1623                    return SqlRuleFilterExtensions.ParseFromXElement(xElement);
 24                case "CorrelationFilter":
 2025                    return CorrelationRuleFilterExtensions.ParseFromXElement(xElement);
 26                case "TrueFilter":
 1227                    return new TrueRuleFilter();
 28                case "FalseFilter":
 029                    return new FalseRuleFilter();
 30                default:
 031                    ServiceBusEventSource.Log.ManagementSerializationException(
 032                        $"{nameof(RuleFilterExtensions)}_{nameof(ParseFromXElement)}",
 033                        xElement.ToString());
 034                    return null;
 35            }
 36        }
 37
 38        public static XElement Serialize(this RuleFilter filter)
 39        {
 40            switch (filter)
 41            {
 42                case SqlRuleFilter sqlRuleFilter:
 43                    switch (sqlRuleFilter)
 44                    {
 45                        case TrueRuleFilter _:
 2846                            return sqlRuleFilter.Serialize("TrueFilter");
 47
 48                        case FalseRuleFilter _:
 049                            return sqlRuleFilter.Serialize("FalseFilter");
 50
 51                        default:
 852                            return sqlRuleFilter.Serialize("SqlFilter");
 53                    }
 54
 55                case CorrelationRuleFilter correlationRuleFilter:
 1256                    return correlationRuleFilter.Serialize("CorrelationFilter");
 57
 58                default:
 059                    throw new NotImplementedException($"filter type {filter.GetType().Name} is not supported.");
 60            }
 61        }
 62    }
 63}