< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.SynchronizedChannelCollection<T>
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/SynchronizedChannelCollection.cs
Line coverage
12%
Covered lines: 4
Uncovered lines: 29
Coverable lines: 33
Total lines: 83
Line coverage: 12.1%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%11100%
AddingChannel(...)100%110%
RemovingChannel(...)100%110%
OnChannelClosed(...)100%110%
OnChannelFaulted(...)100%110%
ClearItems()0%220%
InsertItem(...)100%110%
RemoveItem(...)100%110%
SetItem(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/SynchronizedChannelCollection.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;
 6using CoreWCF.Channels;
 7using CoreWCF.Collections.Generic;
 8
 9namespace CoreWCF.Dispatcher
 10{
 11    internal class SynchronizedChannelCollection<TChannel> : SynchronizedCollection<TChannel>
 12        where TChannel : IChannel
 13    {
 14        private readonly EventHandler _onChannelClosed;
 15        private readonly EventHandler _onChannelFaulted;
 16
 17        internal SynchronizedChannelCollection(object syncRoot)
 66318            : base(syncRoot)
 19        {
 66320            _onChannelClosed = new EventHandler(OnChannelClosed);
 66321            _onChannelFaulted = new EventHandler(OnChannelFaulted);
 66322        }
 23
 24        private void AddingChannel(TChannel channel)
 25        {
 026            channel.Faulted += _onChannelFaulted;
 027            channel.Closed += _onChannelClosed;
 028        }
 29
 30        private void RemovingChannel(TChannel channel)
 31        {
 032            channel.Faulted -= _onChannelFaulted;
 033            channel.Closed -= _onChannelClosed;
 034        }
 35
 36        private void OnChannelClosed(object sender, EventArgs args)
 37        {
 038            TChannel channel = (TChannel)sender;
 039            Remove(channel);
 040        }
 41
 42        private void OnChannelFaulted(object sender, EventArgs args)
 43        {
 044            TChannel channel = (TChannel)sender;
 045            Remove(channel);
 046        }
 47
 48        protected override void ClearItems()
 49        {
 050            List<TChannel> items = Items;
 51
 052            for (int i = 0; i < items.Count; i++)
 53            {
 054                RemovingChannel(items[i]);
 55            }
 56
 057            base.ClearItems();
 058        }
 59
 60        protected override void InsertItem(int index, TChannel item)
 61        {
 062            AddingChannel(item);
 063            base.InsertItem(index, item);
 064        }
 65
 66        protected override void RemoveItem(int index)
 67        {
 068            TChannel oldItem = Items[index];
 69
 070            base.RemoveItem(index);
 071            RemovingChannel(oldItem);
 072        }
 73
 74        protected override void SetItem(int index, TChannel item)
 75        {
 076            TChannel oldItem = Items[index];
 77
 078            AddingChannel(item);
 079            base.SetItem(index, item);
 080            RemovingChannel(oldItem);
 081        }
 82    }
 83}