< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.Tokens.SecurityToken
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SecurityToken.cs
Line coverage
58%
Covered lines: 7
Uncovered lines: 5
Coverable lines: 12
Total lines: 57
Line coverage: 58.3%
Branch coverage
41%
Covered branches: 5
Total branches: 12
Branch coverage: 41.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CanCreateKeyIdentifierClause()0%220%
CreateKeyIdentifierClause()50%4450%
MatchesKeyIdentifierClause(...)50%2266.66%
ResolveKeyIdentifierClause(...)50%4466.66%
CanCreateLocalKeyIdentifierClause()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/Tokens/SecurityToken.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.ObjectModel;
 6
 7namespace CoreWCF.IdentityModel.Tokens
 8{
 9    public abstract class SecurityToken
 10    {
 11        public abstract string Id { get; }
 12        public abstract ReadOnlyCollection<SecurityKey> SecurityKeys { get; }
 13        public abstract DateTime ValidFrom { get; }
 14        public abstract DateTime ValidTo { get; }
 15
 16        public virtual bool CanCreateKeyIdentifierClause<T>() where T : SecurityKeyIdentifierClause
 17        {
 018            return ((typeof(T) == typeof(LocalIdKeyIdentifierClause)) && CanCreateLocalKeyIdentifierClause());
 19        }
 20
 21        public virtual T CreateKeyIdentifierClause<T>() where T : SecurityKeyIdentifierClause
 22        {
 1023            if ((typeof(T) == typeof(LocalIdKeyIdentifierClause)) && CanCreateLocalKeyIdentifierClause())
 24            {
 1025                return new LocalIdKeyIdentifierClause(Id, GetType()) as T;
 26            }
 27
 028            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(
 029                SR.Format(SR.TokenDoesNotSupportKeyIdentifierClauseCreation, GetType().Name, typeof(T).Name)));
 30        }
 31
 32        public virtual bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
 33        {
 2334            if (keyIdentifierClause is LocalIdKeyIdentifierClause localKeyIdentifierClause)
 35            {
 2336                return localKeyIdentifierClause.Matches(Id, GetType());
 37            }
 38
 039            return false;
 40        }
 41
 42        public virtual SecurityKey ResolveKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
 43        {
 144            if (SecurityKeys.Count != 0 && MatchesKeyIdentifierClause(keyIdentifierClause))
 45            {
 146                return SecurityKeys[0];
 47            }
 48
 049            return null;
 50        }
 51
 52        private bool CanCreateLocalKeyIdentifierClause()
 53        {
 1054            return (Id != null);
 55        }
 56    }
 57}