< Summary

Class:Azure.Messaging.ServiceBus.Management.AuthorizationRules
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Management\AuthorizationRules.cs
Covered lines:24
Uncovered lines:11
Coverable lines:35
Total lines:120
Line coverage:68.5% (24 of 35)
Covered branches:14
Total branches:22
Branch coverage:63.6% (14 of 22)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Serialize()-100%100%
Clone()-100%100%
.ctor()-100%100%
ParseFromXElement(...)-100%100%
GetHashCode()-0%0%
Equals(...)-0%100%
Equals(...)-70%66.67%
op_Equality(...)-60%66.67%
op_Inequality(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using System.Xml.Linq;
 8
 9namespace Azure.Messaging.ServiceBus.Management
 10{
 11    /// <summary>
 12    /// Specifies the authorization rules.
 13    /// </summary>
 14    public class AuthorizationRules : List<AuthorizationRule>, IEquatable<AuthorizationRules>
 15    {
 16        internal XElement Serialize()
 17        {
 8018            var rules = new XElement(
 8019                XName.Get("AuthorizationRules", ManagementClientConstants.ServiceBusNamespace),
 9620                this.Select(rule => rule.Serialize()));
 21
 8022            return rules;
 23        }
 24
 25        internal AuthorizationRules Clone()
 26        {
 2827            var rules = new AuthorizationRules();
 9628            foreach (AuthorizationRule rule in this)
 29            {
 2030                rules.Add(rule.Clone());
 31            }
 2832            return rules;
 33        }
 34
 78035        internal AuthorizationRules() { }
 36
 37        internal static AuthorizationRules ParseFromXElement(XElement xElement)
 38        {
 9239            var rules = new AuthorizationRules();
 9240            var xRules = xElement.Elements(XName.Get("AuthorizationRule", ManagementClientConstants.ServiceBusNamespace)
 13241            rules.AddRange(xRules.Select(rule => AuthorizationRule.ParseFromXElement(rule)));
 9242            return rules;
 43        }
 44
 45        /// <summary>
 46        ///   Returns a hash code for this instance.
 47        /// </summary>
 48        public override int GetHashCode()
 49        {
 050            int hash = 7;
 51            unchecked
 52            {
 053                foreach (AuthorizationRule rule in this)
 54                {
 055                    hash = (hash * 7) + rule.GetHashCode();
 56                }
 57            }
 58
 059            return hash;
 60        }
 61
 62        /// <summary>
 63        /// Determines whether the specified object is equal to the current object.
 64        /// </summary>
 65        public override bool Equals(object obj)
 66        {
 067            var other = obj as AuthorizationRules;
 068            return Equals(other);
 69        }
 70
 71        /// <summary>
 72        /// Determines whether the specified object is equal to the current object.
 73        /// </summary>
 74        public bool Equals(AuthorizationRules other)
 75        {
 3276            if (other is null || Count != other.Count)
 77            {
 078                return false;
 79            }
 80
 3281            var cnt = new Dictionary<string, AuthorizationRule>();
 11282            foreach (AuthorizationRule rule in this)
 83            {
 2484                cnt[rule.KeyName] = rule;
 85            }
 86
 11287            foreach (AuthorizationRule otherRule in other)
 88            {
 2489                if (!cnt.TryGetValue(otherRule.KeyName, out var rule) || !rule.Equals(otherRule))
 90                {
 091                    return false;
 92                }
 93            }
 94
 3295            return true;
 096        }
 97
 98        /// <summary></summary>
 99        public static bool operator ==(AuthorizationRules left, AuthorizationRules right)
 100        {
 96101            if (ReferenceEquals(left, right))
 102            {
 0103                return true;
 104            }
 105
 96106            if (left is null || right is null)
 107            {
 96108                return false;
 109            }
 110
 0111            return left.Equals(right);
 112        }
 113
 114        /// <summary></summary>
 115        public static bool operator !=(AuthorizationRules left, AuthorizationRules right)
 116        {
 64117            return !(left == right);
 118        }
 119    }
 120}