< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.SecurityTokenHandlerCollectionManager
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SecurityTokenHandlerCollectionManager.cs
Line coverage
66%
Covered lines: 12
Uncovered lines: 6
Coverable lines: 18
Total lines: 124
Line coverage: 66.6%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
.ctor()100%110%
CreateEmptySecurityTokenHandlerCollectionManager()100%11100%
ContainsKey(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SecurityTokenHandlerCollectionManager.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections.Generic;
 6using CoreWCF.IdentityModel.Configuration;
 7
 8namespace CoreWCF.IdentityModel.Tokens
 9{
 10    /// <summary>
 11    /// A class which manages multiple named <see cref="SecurityTokenHandlerCollection"/>.
 12    /// </summary>
 13    public class SecurityTokenHandlerCollectionManager
 14    {
 215        private readonly Dictionary<string, SecurityTokenHandlerCollection> _collections = new Dictionary<string, Securi
 16
 17        /// <summary>
 18        /// Initialize an instance of <see cref="SecurityTokenHandlerCollectionManager"/> for a given named service.
 19        /// </summary>
 20        /// <param name="serviceName">A <see cref="String"/> indicating the name of the associated service.</param>
 221        public SecurityTokenHandlerCollectionManager(string serviceName)
 22        {
 223            ServiceName = serviceName ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(service
 224        }
 25
 26        /// <summary>
 27        /// Initialized with default service configuration.
 28        /// </summary>
 29        private SecurityTokenHandlerCollectionManager()
 030            : this(ConfigurationStrings.DefaultServiceName)
 31        {
 032        }
 33
 34        /// <summary>
 35        /// Gets a count of the number of SecurityTokenHandlerCollections in this
 36        /// SecurityTokenHandlerCollectionManager.
 37        /// </summary>
 038        public int Count => _collections.Count;
 39
 40        /// <summary>
 41        ///  Gets the service name.
 42        /// </summary>
 243        public string ServiceName { get; } = ConfigurationStrings.DefaultServiceName;
 44
 45        /// <summary>
 46        /// Gets an enumeration over the SecurityTokenHandlerCollection list.
 47        /// </summary>
 048        public IEnumerable<SecurityTokenHandlerCollection> SecurityTokenHandlerCollections => _collections.Values;
 49
 50        /// <summary>
 51        /// The SecurityTokenHandlerCollection for the specified usage.
 52        /// </summary>
 53        /// <param name=nameof(usage)>The usage name for the SecurityTokenHandlerCollection.</param>
 54        /// <returns>A SecurityTokenHandlerCollection</returns>
 55        /// <remarks>
 56        /// Behaves like a dictionary in that it will throw an exception if there is no
 57        /// value for the specified key.
 58        /// </remarks>
 59        public SecurityTokenHandlerCollection this[string usage]
 60        {
 61            get
 62            {
 63                // Empty String is valid (Usage.Default)
 264                if (null == usage)
 65                {
 066                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(usage));
 67                }
 68
 269                return _collections[usage];
 70            }
 71
 72            set
 73            {
 74                // Empty String is valid (Usage.Default)
 275                if (null == usage)
 76                {
 077                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(usage));
 78                }
 79
 280                _collections[usage] = value;
 281            }
 82        }
 83
 84        /// <summary>
 85        /// No token handlers are created.
 86        /// </summary>
 87        /// <returns>An empty token handler collection manager.</returns>
 88        public static SecurityTokenHandlerCollectionManager CreateEmptySecurityTokenHandlerCollectionManager()
 89        {
 290            return new SecurityTokenHandlerCollectionManager(ConfigurationStrings.DefaultConfigurationElementName);
 91        }
 92
 93        /// <summary>
 94        /// Checks if a SecurityTokenHandlerCollection exists for the given usage.
 95        /// </summary>
 96        /// <param name=nameof(usage)>A string that represents the usage of the SecurityTokenHandlerCollection.</param>
 97        /// <returns>Whether or not a token handler collection exists for the given usage.</returns>
 98        public bool ContainsKey(string usage)
 99        {
 2100            return _collections.ContainsKey(usage);
 101        }
 102
 103        /// <summary>
 104        /// Defines standard collection names used by the framework.
 105        /// </summary>
 106        public static class Usage
 107        {
 108            /// <summary>
 109            /// Used to reference the default collection of handlers.
 110            /// </summary>
 111            public const string Default = "";
 112
 113            /// <summary>
 114            /// Used to reference a collection of handlers for ActAs element processing.
 115            /// </summary>
 116            public const string ActAs = "ActAs";
 117
 118            /// <summary>
 119            /// Used to reference a collection of handlers for OnBehalfOf element processing.
 120            /// </summary>
 121            public const string OnBehalfOf = "OnBehalfOf";
 122        }
 123    }
 124}