< Summary - CoreWCF Coverage — PR #1766

Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 50
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetCurrentUpn(...)0%880%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/Interop/Windows/Secur32/Interop.GetUserNameExW.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.Runtime.InteropServices;
 5using System.Text;
 6
 7internal static partial class Interop
 8{
 9    internal static partial class Secur32
 10    {
 11        internal static bool GetCurrentUpn(out string upn)
 12        {
 013            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 14            {
 015                upn = null;
 016                return false;
 17            }
 18
 019            StringBuilder sb = new StringBuilder(1024);
 020            uint upnNameLength = (uint)sb.Capacity;
 21
 022            if (GetUserNameEx(EXTENDED_NAME_FORMAT.NameUserPrincipal, sb, ref upnNameLength) == BOOLEAN.FALSE)
 23            {
 024                int error = Marshal.GetLastWin32Error();
 025                if (error == ERROR_MORE_DATA)
 26                {
 027                    sb.Capacity = (int)++upnNameLength;
 028                    if (GetUserNameEx(EXTENDED_NAME_FORMAT.NameUserPrincipal, sb, ref upnNameLength) == BOOLEAN.FALSE)
 29                    {
 030                        upn = null;
 031                        return false;
 32                    }
 33                }
 34                else
 35                {
 036                    upn = null;
 037                    return false;
 38                }
 39            }
 40
 041            upn = sb.ToString();
 042            return true;
 43        }
 44
 45        internal const int ERROR_MORE_DATA = 0xEA;
 46
 47        [DllImport("secur32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
 48        internal static extern BOOLEAN GetUserNameEx(EXTENDED_NAME_FORMAT nameFormat, [Out] StringBuilder lpNameBuffer, 
 49    }
 50}

Methods/Properties

GetCurrentUpn(System.String&)