< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ConnectionLogScope
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/ConnectionLogScope.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 67
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
GetEnumerator()0%220%
System.Collections.IEnumerable.GetEnumerator()100%110%
ToString()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/ConnectionLogScope.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;
 6using System.Collections.Generic;
 7using System.Globalization;
 8using System.Text;
 9
 10namespace CoreWCF.Channels
 11{
 12    // Copied from Microsoft.AspNetCore.Server.Kestrel.Core.Internal.ConnectionLogScope
 13    // This class is used to add the connection ID to the log scope in a lightweight way.
 14    // A Dictionary is too heavy weight for this simple usage.
 15    internal sealed class ConnectionLogScope : IReadOnlyList<KeyValuePair<string, object>>
 16    {
 17        private readonly string _connectionId;
 18
 19        private string _cachedToString;
 20
 021        public ConnectionLogScope(string connectionId)
 22        {
 023            _connectionId = connectionId;
 024        }
 25
 26        public KeyValuePair<string, object> this[int index]
 27        {
 28            get
 29            {
 030                if (index == 0)
 31                {
 032                    return new KeyValuePair<string, object>("ConnectionId", _connectionId);
 33                }
 34
 035                throw new ArgumentOutOfRangeException(nameof(index));
 36            }
 37        }
 38
 039        public int Count => 1;
 40
 41        public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
 42        {
 043            for (int i = 0; i < Count; ++i)
 44            {
 045                yield return this[i];
 46            }
 047        }
 48
 49        IEnumerator IEnumerable.GetEnumerator()
 50        {
 051            return GetEnumerator();
 52        }
 53
 54        public override string ToString()
 55        {
 056            if (_cachedToString == null)
 57            {
 058                _cachedToString = string.Format(
 059                    CultureInfo.InvariantCulture,
 060                    "ConnectionId:{0}",
 061                    _connectionId);
 62            }
 63
 064            return _cachedToString;
 65        }
 66    }
 67}