< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.ExtensionCollection<T>
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/ExtensionCollection.cs
Line coverage
56%
Covered lines: 28
Uncovered lines: 22
Coverable lines: 50
Total lines: 126
Line coverage: 56%
Branch coverage
37%
Covered branches: 6
Total branches: 16
Branch coverage: 37.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%2280%
.ctor(...)50%2280%
ClearItems()0%220%
Find()75%44100%
FindAll()0%440%
InsertItem(...)50%2285.71%
RemoveItem(...)100%11100%
SetItem(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/ExtensionCollection.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 System.Collections.ObjectModel;
 7using CoreWCF.Collections.Generic;
 8
 9namespace CoreWCF
 10{
 11    public sealed class ExtensionCollection<T> : SynchronizedCollection<IExtension<T>>, IExtensionCollection<T>
 12        where T : IExtensibleObject<T>
 13    {
 14        private readonly T _owner;
 15
 3416        public ExtensionCollection(T owner)
 17        {
 3418            if (owner == null)
 19            {
 020                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(owner));
 21            }
 22
 3423            _owner = owner;
 3424        }
 25
 26        public ExtensionCollection(T owner, object syncRoot)
 257627            : base(syncRoot)
 28        {
 257629            if (owner == null)
 30            {
 031                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(owner));
 32            }
 33
 257634            _owner = owner;
 257635        }
 36
 37        bool ICollection<IExtension<T>>.IsReadOnly
 38        {
 039            get { return false; }
 40        }
 41
 42        protected override void ClearItems()
 43        {
 44            IExtension<T>[] array;
 45
 046            lock (SyncRoot)
 47            {
 048                array = new IExtension<T>[Count];
 049                CopyTo(array, 0);
 050                base.ClearItems();
 51
 052                foreach (IExtension<T> extension in array)
 53                {
 054                    extension.Detach(_owner);
 55                }
 056            }
 057        }
 58
 59        public TE Find<TE>()
 60        {
 440961            List<IExtension<T>> items = Items;
 62
 440963            lock (SyncRoot)
 64            {
 881865                for (int i = Count - 1; i >= 0; i--)
 66                {
 200567                    IExtension<T> item = items[i];
 200568                    if (item is TE)
 69                    {
 200570                        return (TE)item;
 71                    }
 72                }
 240473            }
 74
 240475            return default;
 200576        }
 77
 78        public Collection<TE> FindAll<TE>()
 79        {
 080            Collection<TE> result = new Collection<TE>();
 081            List<IExtension<T>> items = Items;
 82
 083            lock (SyncRoot)
 84            {
 085                for (int i = 0; i < items.Count; i++)
 86                {
 087                    IExtension<T> item = items[i];
 088                    if (item is TE)
 89                    {
 090                        result.Add((TE)item);
 91                    }
 92                }
 093            }
 94
 095            return result;
 96        }
 97
 98        protected override void InsertItem(int index, IExtension<T> item)
 99        {
 2595100            if (item == null)
 101            {
 0102                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item));
 103            }
 104
 2595105            lock (SyncRoot)
 106            {
 2595107                item.Attach(_owner);
 2595108                base.InsertItem(index, item);
 2595109            }
 2595110        }
 111
 112        protected override void RemoveItem(int index)
 113        {
 1906114            lock (SyncRoot)
 115            {
 1906116                Items[index].Detach(_owner);
 1906117                base.RemoveItem(index);
 1906118            }
 1906119        }
 120
 121        protected override void SetItem(int index, IExtension<T> item)
 122        {
 0123            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxCannotSetExten
 124        }
 125    }
 126}