< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.CommunicationObjectManager<T>
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/CommunicationObjectManager.cs
Line coverage
45%
Covered lines: 18
Uncovered lines: 22
Coverable lines: 40
Total lines: 101
Line coverage: 45%
Branch coverage
50%
Covered branches: 6
Total branches: 12
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
Add(...)75%8878.57%
CloseInput()100%110%
DecrementActivityCount()100%11100%
IncrementActivityCount()100%11100%
OnItemClosed(...)100%110%
Remove(...)0%220%
ToArray()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/CommunicationObjectManager.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.Generic;
 6
 7namespace CoreWCF.Channels
 8{
 9    internal class CommunicationObjectManager<TItemType> : LifetimeManager where TItemType : class, ICommunicationObject
 10    {
 11        private bool _inputClosed;
 12        private readonly ISet<TItemType> _itemsSet;
 13
 14        public CommunicationObjectManager(object mutex)
 66315            : base(mutex)
 16        {
 66317            _itemsSet = new HashSet<TItemType>();
 66318        }
 19
 20        public void Add(TItemType item)
 21        {
 1322            bool added = false;
 23
 1324            lock (ThisLock)
 25            {
 1326                if (State == LifetimeState.Opened && !_inputClosed)
 27                {
 1328                    if (_itemsSet.Contains(item))
 29                    {
 030                        return;
 31                    }
 32
 1333                    _itemsSet.Add(item);
 1334                    IncrementBusyCountWithoutLock();
 1335                    item.Closed += OnItemClosed;
 1336                    added = true;
 37                }
 1338            }
 39
 1340            if (!added)
 41            {
 042                item.Abort();
 043                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ObjectDisposedException(GetType().ToString
 44            }
 1345        }
 46
 47        public void CloseInput()
 48        {
 49            //Abort can reenter this call as a result of
 50            //close timeout, Closing input twice is not a
 51            //FailFast case.
 052            _inputClosed = true;
 053        }
 54
 55        public void DecrementActivityCount()
 56        {
 12857            DecrementBusyCount();
 12858        }
 59
 60        public void IncrementActivityCount()
 61        {
 231862            IncrementBusyCount();
 231863        }
 64
 65        private void OnItemClosed(object sender, EventArgs args)
 66        {
 067            Remove((TItemType)sender);
 068        }
 69
 70        public void Remove(TItemType item)
 71        {
 072            lock (ThisLock)
 73            {
 074                if (!_itemsSet.Contains(item))
 75                {
 076                    return;
 77                }
 78
 079                _itemsSet.Remove(item);
 080            }
 81
 082            item.Closed -= OnItemClosed;
 083            DecrementBusyCount();
 084        }
 85
 86        public TItemType[] ToArray()
 87        {
 088            lock (ThisLock)
 89            {
 090                int index = 0;
 091                TItemType[] items = new TItemType[_itemsSet.Count];
 092                foreach (TItemType item in _itemsSet)
 93                {
 094                    items[index++] = item;
 95                }
 96
 097                return items;
 98            }
 099        }
 100    }
 101}