< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.Framing.ConnectionContextExtensions
Assembly: CoreWCF.NetFramingBase
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/Framing/ConnectionContextExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 44
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
Set(...)0%220%
Replace(...)0%220%
Get(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetFramingBase/src/CoreWCF/Channels/Framing/ConnectionContextExtensions.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 Microsoft.AspNetCore.Connections;
 6
 7namespace CoreWCF.Channels.Framing
 8{
 9    internal static class ConnectionContextExtensions
 10    {
 11        public static void Set<T>(this ConnectionContext context, T value)
 12        {
 013            if (context.Items.ContainsKey(typeof(T)))
 14            {
 015                throw new ArgumentException(nameof(T));
 16            }
 17
 018            context.Items[typeof(T)] = value;
 019        }
 20
 21        public static void Replace<T>(this ConnectionContext context, T value)
 22        {
 023            if (!context.Items.ContainsKey(typeof(T)))
 24            {
 025                throw new ArgumentException(nameof(T));
 26            }
 27
 028            context.Items[typeof(T)] = value;
 029        }
 30
 31        public static T Get<T>(this ConnectionContext context)
 32        {
 033            if (context.Items.TryGetValue(typeof(T), out object item))
 34            {
 035                if (item is T)
 36                {
 037                    return (T)item;
 38                }
 39            }
 40
 041            return default;
 42        }
 43    }
 44}