< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ChannelBindingMessageProperty
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/ChannelBindingMessageProperty.cs
Line coverage
20%
Covered lines: 7
Uncovered lines: 28
Coverable lines: 35
Total lines: 107
Line coverage: 20%
Branch coverage
16%
Covered branches: 3
Total branches: 18
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%220%
TryGet(...)50%2266.66%
TryGet(...)50%4457.14%
CoreWCF.Channels.IMessageProperty.CreateCopy()100%110%
System.IDisposable.Dispose()0%880%
ThrowIfDisposed()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/ChannelBindingMessageProperty.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.Security.Authentication.ExtendedProtection;
 6
 7namespace CoreWCF.Channels
 8{
 9    public sealed class ChannelBindingMessageProperty : IDisposable, IMessageProperty
 10    {
 11        internal const string PropertyName = "ChannelBindingMessageProperty";
 12        private readonly ChannelBinding _channelBinding;
 13        private readonly object _thisLock;
 14        private readonly bool _ownsCleanup;
 15        private int _refCount;
 16
 017        public ChannelBindingMessageProperty(ChannelBinding channelBinding, bool ownsCleanup)
 18        {
 019            _channelBinding = channelBinding ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(
 020            _refCount = 1;
 021            _thisLock = new object();
 022            _ownsCleanup = ownsCleanup;
 023        }
 24
 15725        public static string Name { get { return PropertyName; } }
 26
 27        private bool IsDisposed
 28        {
 29            get
 30            {
 031                return _refCount <= 0;
 32            }
 33        }
 34
 35        public ChannelBinding ChannelBinding
 36        {
 37            get
 38            {
 039                ThrowIfDisposed();
 040                return _channelBinding;
 41            }
 42        }
 43
 44        public static bool TryGet(Message message, out ChannelBindingMessageProperty property)
 45        {
 15746            if (message == null)
 47            {
 048                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
 49            }
 50
 15751            return TryGet(message.Properties, out property);
 52        }
 53
 54        public static bool TryGet(MessageProperties properties, out ChannelBindingMessageProperty property)
 55        {
 15756            if (properties == null)
 57            {
 058                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(properties));
 59            }
 60
 15761            property = null;
 62
 15763            if (properties.TryGetValue(Name, out object value))
 64            {
 065                property = value as ChannelBindingMessageProperty;
 066                return property != null;
 67            }
 68
 15769            return false;
 70        }
 71        IMessageProperty IMessageProperty.CreateCopy()
 72        {
 073            lock (_thisLock)
 74            {
 075                ThrowIfDisposed();
 076                _refCount++;
 077                return this;
 78            }
 079        }
 80
 81        void IDisposable.Dispose()
 82        {
 083            if (!IsDisposed)
 84            {
 085                lock (_thisLock)
 86                {
 087                    if (!IsDisposed && --_refCount == 0)
 88                    {
 089                        if (_ownsCleanup)
 90                        {
 91                            // Accessing via IDisposable to avoid Security check (functionally the same)
 092                            ((IDisposable)_channelBinding).Dispose();
 93                        }
 94                    }
 095                }
 96            }
 097        }
 98
 99        private void ThrowIfDisposed()
 100        {
 0101            if (IsDisposed)
 102            {
 0103                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(GetType().FullName
 104            }
 0105        }
 106    }
 107}