< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.ProtectionLevelHelper
Assembly: CoreWCF.NetTcp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/Security/ProtectionLevelHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 68
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 24
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
IsDefined(...)0%440%
Validate(...)0%220%
IsStronger(...)0%660%
IsStrongerOrEqual(...)0%440%
Max(...)0%220%
GetOrdinal(...)0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/Security/ProtectionLevelHelper.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.ComponentModel;
 6using System.Net.Security;
 7
 8namespace CoreWCF.Security
 9{
 10    internal static class ProtectionLevelHelper
 11    {
 12        internal static bool IsDefined(ProtectionLevel value)
 13        {
 014            return (value == ProtectionLevel.None
 015                || value == ProtectionLevel.Sign
 016                || value == ProtectionLevel.EncryptAndSign);
 17        }
 18
 19        internal static void Validate(ProtectionLevel value)
 20        {
 021            if (!IsDefined(value))
 22            {
 023                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException(nameof(value)
 024                    typeof(ProtectionLevel)));
 25            }
 026        }
 27
 28        internal static bool IsStronger(ProtectionLevel v1, ProtectionLevel v2)
 29        {
 030            return ((v1 == ProtectionLevel.EncryptAndSign && v2 != ProtectionLevel.EncryptAndSign)
 031                    || (v1 == ProtectionLevel.Sign && v2 == ProtectionLevel.None));
 32        }
 33
 34        internal static bool IsStrongerOrEqual(ProtectionLevel v1, ProtectionLevel v2)
 35        {
 036            return (v1 == ProtectionLevel.EncryptAndSign
 037                    || (v1 == ProtectionLevel.Sign && v2 != ProtectionLevel.EncryptAndSign));
 38        }
 39
 40        internal static ProtectionLevel Max(ProtectionLevel v1, ProtectionLevel v2)
 41        {
 042            return IsStronger(v1, v2) ? v1 : v2;
 43        }
 44
 45        internal static int GetOrdinal(Nullable<ProtectionLevel> p)
 46        {
 047            if (p.HasValue)
 48            {
 049                switch ((ProtectionLevel)p)
 50                {
 51                    default:
 052                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException(nameo
 053                        typeof(ProtectionLevel)));
 54                    case ProtectionLevel.None:
 055                        return 2;
 56                    case ProtectionLevel.Sign:
 057                        return 3;
 58                    case ProtectionLevel.EncryptAndSign:
 059                        return 4;
 60                }
 61            }
 62            else
 63            {
 064                return 1;
 65            }
 66        }
 67    }
 68}