< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.BindingElementCollection
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/BindingElementCollection.cs
Line coverage
50%
Covered lines: 31
Uncovered lines: 30
Coverable lines: 61
Total lines: 172
Line coverage: 50.8%
Branch coverage
44%
Covered branches: 17
Total branches: 38
Branch coverage: 44.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)75%4483.33%
.ctor(...)0%440%
Clone()100%22100%
AddRange(...)0%440%
Contains(...)0%660%
Find()100%11100%
Remove()100%11100%
Find(...)100%66100%
FindAll()100%11100%
RemoveAll()100%110%
FindAll(...)83.33%6677.77%
InsertItem(...)50%2275%
SetItem(...)0%220%
Reverse()0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/BindingElementCollection.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;
 7
 8namespace CoreWCF.Channels
 9{
 10    public class BindingElementCollection : Collection<BindingElement>
 11    {
 3025512        public BindingElementCollection()
 13        {
 3025514        }
 15
 2204516        public BindingElementCollection(IEnumerable<BindingElement> elements)
 17        {
 2204518            if (elements == null)
 19            {
 020                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elements));
 21            }
 22
 12032823            foreach (BindingElement element in elements)
 24            {
 3811925                Add(element);
 26            }
 2204527        }
 28
 029        public BindingElementCollection(BindingElement[] elements)
 30        {
 031            if (elements == null)
 32            {
 033                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elements));
 34            }
 35
 036            for (int i = 0; i < elements.Length; i++)
 37            {
 038                Add(elements[i]);
 39            }
 040        }
 41
 42        // returns a new collection with clones of all the elements
 43        public BindingElementCollection Clone()
 44        {
 1131445            BindingElementCollection result = new BindingElementCollection();
 6896646            for (int i = 0; i < Count; i++)
 47            {
 2316948                result.Add(this[i].Clone());
 49            }
 1131450            return result;
 51        }
 52
 53        public void AddRange(params BindingElement[] elements)
 54        {
 055            if (elements == null)
 56            {
 057                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elements));
 58            }
 59
 060            for (int i = 0; i < elements.Length; i++)
 61            {
 062                Add(elements[i]);
 63            }
 064        }
 65
 66        public bool Contains(Type bindingElementType)
 67        {
 068            if (bindingElementType == null)
 69            {
 070                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(bindingElementType));
 71            }
 72
 073            for (int i = 0; i < Count; i++)
 74            {
 075                if (bindingElementType.IsInstanceOfType(this[i]))
 76                {
 077                    return true;
 78                }
 79            }
 080            return false;
 81        }
 82
 83        public T Find<T>()
 84        {
 461385            return Find<T>(false);
 86        }
 87
 88        public T Remove<T>()
 89        {
 1278590            return Find<T>(true);
 91        }
 92
 93        private T Find<T>(bool remove)
 94        {
 4311695            for (int index = 0; index < Count; index++)
 96            {
 2155297                if (this[index] is T)
 98                {
 1739299                    T item = (T)(object)this[index];
 17392100                    if (remove)
 101                    {
 12785102                        RemoveAt(index);
 103                    }
 17392104                    return item;
 105                }
 106            }
 6107            return default;
 108        }
 109
 110        public Collection<T> FindAll<T>()
 111        {
 73112            return FindAll<T>(false);
 113        }
 114
 115        public Collection<T> RemoveAll<T>()
 116        {
 0117            return FindAll<T>(true);
 118        }
 119
 120        private Collection<T> FindAll<T>(bool remove)
 121        {
 73122            Collection<T> collection = new Collection<T>();
 123
 496124            for (int index = 0; index < Count; index++)
 125            {
 175126                if (this[index] is T)
 127                {
 146128                    T item = (T)(object)this[index];
 146129                    if (remove)
 130                    {
 0131                        RemoveAt(index);
 132                        // back up the index so we inspect the new item at this location
 0133                        index--;
 134                    }
 146135                    collection.Add(item);
 136                }
 137            }
 138
 73139            return collection;
 140        }
 141        protected override void InsertItem(int index, BindingElement item)
 142        {
 96419143            if (item == null)
 144            {
 0145                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item));
 146            }
 147
 96419148            base.InsertItem(index, item);
 96419149        }
 150
 151        protected override void SetItem(int index, BindingElement item)
 152        {
 0153            if (item == null)
 154            {
 0155                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item));
 156            }
 157
 0158            base.SetItem(index, item);
 0159        }
 160
 161        internal BindingElementCollection Reverse()
 162        {
 0163            var bec = new BindingElementCollection();
 0164            for (int i = Count - 1; i >= 0; i--)
 165            {
 0166                bec.Add(this[i]);
 167            }
 168
 0169            return bec;
 170        }
 171    }
 172}