< Summary

Class:Microsoft.Azure.ServiceBus.Management.AuthorizationRules
Assembly:Microsoft.Azure.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Management\AuthorizationRules.cs
Covered lines:0
Uncovered lines:31
Coverable lines:31
Total lines:96
Line coverage:0% (0 of 31)
Covered branches:0
Total branches:20
Branch coverage:0% (0 of 20)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_RequiresEncryption()-0%100%
Serialize()-0%100%
ParseFromXElement(...)-0%100%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-0%0%
op_Equality(...)-0%0%
op_Inequality(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Microsoft.Azure.ServiceBus\src\Management\AuthorizationRules.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.Management
 5{
 6    using System;
 7    using System.Collections.Generic;
 8    using System.Linq;
 9    using System.Xml.Linq;
 10
 11    public class AuthorizationRules : List<AuthorizationRule>, IEquatable<AuthorizationRules>
 12    {
 013        private bool RequiresEncryption => this.Count > 0;
 14
 15        internal XElement Serialize()
 16        {
 017            var rules = new XElement(
 018                XName.Get("AuthorizationRules", ManagementClientConstants.ServiceBusNamespace),
 019                this.Select(rule => rule.Serialize()));
 20
 021            return rules;
 22        }
 23
 24        internal static AuthorizationRules ParseFromXElement(XElement xElement)
 25        {
 026            var rules = new AuthorizationRules();
 027            var xRules = xElement.Elements(XName.Get("AuthorizationRule", ManagementClientConstants.ServiceBusNamespace)
 028            rules.AddRange(xRules.Select(rule => AuthorizationRule.ParseFromXElement(rule)));
 029            return rules;
 30        }
 31
 32        public override int GetHashCode()
 33        {
 034            int hash = 7;
 35            unchecked
 36            {
 037                foreach (var rule in this)
 38                {
 039                    hash = (hash * 7) + rule.GetHashCode();
 40                }
 41            }
 42
 043            return hash;
 44        }
 45
 46        public override bool Equals(object obj)
 47        {
 048            var other = obj as AuthorizationRules;
 049            return this.Equals(other);
 50        }
 51
 52        public bool Equals(AuthorizationRules other)
 53        {
 054            if (ReferenceEquals(other, null) || this.Count != other.Count)
 55            {
 056                return false;
 57            }
 58
 059            var cnt = new Dictionary<string, AuthorizationRule>();
 060            foreach (AuthorizationRule rule in this)
 61            {
 062                cnt[rule.KeyName] = rule;
 63            }
 64
 065            foreach (AuthorizationRule otherRule in other)
 66            {
 067                if (!cnt.TryGetValue(otherRule.KeyName, out var rule) || !rule.Equals(otherRule))
 68                {
 069                    return false;
 70                }
 71            }
 72
 073            return true;
 074        }
 75
 76        public static bool operator ==(AuthorizationRules o1, AuthorizationRules o2)
 77        {
 078            if (ReferenceEquals(o1, o2))
 79            {
 080                return true;
 81            }
 82
 083            if (ReferenceEquals(o1, null) || ReferenceEquals(o2, null))
 84            {
 085                return false;
 86            }
 87
 088            return o1.Equals(o2);
 89        }
 90
 91        public static bool operator !=(AuthorizationRules o1, AuthorizationRules o2)
 92        {
 093            return !(o1 == o2);
 94        }
 95    }
 96}