< Summary

Class:Azure.Security.KeyVault.Administration.RoleAssignmentScope
Assembly:Azure.Security.KeyVault.Administration
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Administration\src\RoleAssignmentScope.cs
Covered lines:11
Uncovered lines:6
Coverable lines:17
Total lines:96
Line coverage:64.7% (11 of 17)
Covered branches:6
Total branches:10
Branch coverage:60% (6 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%100%
.ctor(...)-100%100%
get_Global()-100%100%
get_Keys()-100%100%
op_Equality(...)-0%100%
op_Inequality(...)-0%100%
op_Implicit(...)-0%100%
Equals(...)-0%0%
Equals(...)-0%100%
GetHashCode()-0%0%
ToString()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Administration\src\RoleAssignmentScope.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.ComponentModel;
 6using Azure.Core;
 7
 8namespace Azure.Security.KeyVault.Administration
 9{
 10    /// <summary>
 11    /// A scope of the role assignment.
 12    /// </summary>
 13    public readonly struct RoleAssignmentScope : IEquatable<RoleAssignmentScope>
 14    {
 15        internal const string GlobalValue = "/";
 16        internal const string KeysValue = "/keys";
 17
 18        private readonly string _value;
 19
 20        /// <summary>
 21        /// Initializes a new instance of the <see cref="RoleAssignmentScope"/> structure.
 22        /// </summary>
 23        /// <param name="value">The string value of the instance.</param>
 24        public RoleAssignmentScope(string value)
 25        {
 1226            _value = value ?? throw new ArgumentNullException(nameof(value));
 827        }
 28
 29        /// <summary>
 30        /// Initializes a new instance of the <see cref="RoleAssignmentScope"/> structure.
 31        /// </summary>
 32        /// <param name="resourceId">The Resource Id for the given Resource.</param>
 33        public RoleAssignmentScope(Uri resourceId)
 34        {
 1835            Argument.AssertNotNull(resourceId, nameof(resourceId));
 36
 37            // Remove the version segment from a Key Id, if present.
 1438            string[] segments = resourceId.Segments;
 39
 1440            if (resourceId.AbsolutePath.StartsWith("/keys/", StringComparison.Ordinal) && segments.Length == 4)
 41            {
 642                _value = resourceId.AbsolutePath.Remove(resourceId.AbsolutePath.Length - segments[3].Length - 1);
 43            }
 44            else
 45            {
 846                _value = resourceId.AbsolutePath;
 47            }
 848        }
 49
 50        /// <summary>
 51        /// Role assignments apply to everything on the resource.
 52        /// </summary>
 8253        public static RoleAssignmentScope Global { get; } = new RoleAssignmentScope(GlobalValue);
 54
 55        /// <summary>
 56        /// Role assignments apply to all Keys.
 57        /// </summary>
 658        public static RoleAssignmentScope Keys { get; } = new RoleAssignmentScope(KeysValue);
 59
 60        /// <summary>
 61        /// Determines if two <see cref="RoleAssignmentScope"/> values are the same.
 62        /// </summary>
 63        /// <param name="left">The first <see cref="RoleAssignmentScope"/> to compare.</param>
 64        /// <param name="right">The second <see cref="RoleAssignmentScope"/> to compare.</param>
 65        /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur
 066        public static bool operator ==(RoleAssignmentScope left, RoleAssignmentScope right) => left.Equals(right);
 67
 68        /// <summary>
 69        /// Determines if two <see cref="RoleAssignmentScope"/> values are different.
 70        /// </summary>
 71        /// <param name="left">The first <see cref="RoleAssignmentScope"/> to compare.</param>
 72        /// <param name="right">The second <see cref="RoleAssignmentScope"/> to compare.</param>
 73        /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu
 074        public static bool operator !=(RoleAssignmentScope left, RoleAssignmentScope right) => !left.Equals(right);
 75
 76        /// <summary>
 77        /// Converts a string to a <see cref="RoleAssignmentScope"/>.
 78        /// </summary>
 79        /// <param name="value">The string value to convert.</param>
 080        public static implicit operator RoleAssignmentScope(string value) => new RoleAssignmentScope(value);
 81
 82        /// <inheritdoc/>
 83        [EditorBrowsable(EditorBrowsableState.Never)]
 084        public override bool Equals(object obj) => obj is RoleAssignmentScope other && Equals(other);
 85
 86        /// <inheritdoc/>
 087        public bool Equals(RoleAssignmentScope other) => string.Equals(_value, other._value, StringComparison.Ordinal);
 88
 89        /// <inheritdoc/>
 90        [EditorBrowsable(EditorBrowsableState.Never)]
 091        public override int GetHashCode() => _value?.GetHashCode() ?? 0;
 92
 93        /// <inheritdoc/>
 9494        public override string ToString() => _value;
 95    }
 96}