< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.PolicyAssertionCollection
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/PolicyAssertionCollection.cs
Line coverage
7%
Covered lines: 4
Uncovered lines: 50
Coverable lines: 54
Total lines: 156
Line coverage: 7.4%
Branch coverage
2%
Covered branches: 1
Total branches: 42
Branch coverage: 2.3%
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(...)0%220%
AddRange(...)0%220%
Contains(...)0%10100%
Find(...)100%110%
Remove(...)100%110%
Find(...)0%12120%
FindAll(...)100%110%
RemoveAll(...)100%110%
FindAll(...)0%12120%
InsertItem(...)50%2275%
SetItem(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/PolicyAssertionCollection.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.Collections.Generic;
 5using System.Collections.ObjectModel;
 6using System.Xml;
 7
 8namespace CoreWCF.Description
 9{
 10    public class PolicyAssertionCollection : Collection<XmlElement>
 11    {
 103612        public PolicyAssertionCollection() { }
 13
 014        public PolicyAssertionCollection(IEnumerable<XmlElement> elements)
 15        {
 016            if (elements == null)
 17            {
 018                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(elements));
 19            }
 20
 021            AddRange(elements);
 022        }
 23
 24        internal void AddRange(IEnumerable<XmlElement> elements)
 25        {
 026            foreach (XmlElement element in elements)
 27            {
 028                Add(element);
 29            }
 030        }
 31
 32        public bool Contains(string localName, string namespaceUri)
 33        {
 034            if (localName == null)
 35            {
 036                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName));
 37            }
 38
 039            if (namespaceUri == null)
 40            {
 041                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(namespaceUri));
 42            }
 43
 044            for (int i = 0; i < Count; i++)
 45            {
 046                XmlElement item = this[i];
 047                if (item.LocalName == localName && item.NamespaceURI == namespaceUri)
 48                {
 049                    return true;
 50                }
 51            }
 52
 053            return false;
 54        }
 55
 56        public XmlElement Find(string localName, string namespaceUri)
 57        {
 058            return Find(localName, namespaceUri, false);
 59        }
 60
 61        public XmlElement Remove(string localName, string namespaceUri)
 62        {
 063            return Find(localName, namespaceUri, true);
 64        }
 65
 66        private XmlElement Find(string localName, string namespaceUri, bool remove)
 67        {
 068            if (localName == null)
 69            {
 070                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName));
 71            }
 72
 073            if (namespaceUri == null)
 74            {
 075                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull((namespaceUri));
 76            }
 77
 078            for (int index = 0; index < Count; index++)
 79            {
 080                XmlElement item = this[index];
 081                if (item.LocalName == localName && item.NamespaceURI == namespaceUri)
 82                {
 083                    if (remove)
 84                    {
 085                        RemoveAt(index);
 86                    }
 087                    return item;
 88                }
 89            }
 90
 091            return null;
 92        }
 93
 94        public Collection<XmlElement> FindAll(string localName, string namespaceUri)
 95        {
 096            return FindAll(localName, namespaceUri, false);
 97        }
 98
 99        public Collection<XmlElement> RemoveAll(string localName, string namespaceUri)
 100        {
 0101            return FindAll(localName, namespaceUri, true);
 102        }
 103
 104        private Collection<XmlElement> FindAll(string localName, string namespaceUri, bool remove)
 105        {
 0106            if (localName == null)
 107            {
 0108                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName));
 109            }
 110
 0111            if (namespaceUri == null)
 112            {
 0113                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(namespaceUri));
 114            }
 115
 0116            Collection<XmlElement> collection = new Collection<XmlElement>();
 117
 0118            for (int index = 0; index < Count; index++)
 119            {
 0120                XmlElement item = this[index];
 0121                if (item.LocalName == localName && item.NamespaceURI == namespaceUri)
 122                {
 0123                    if (remove)
 124                    {
 0125                        RemoveAt(index);
 126                        // back up the index so we inspect the new item at this location
 0127                        index--;
 128                    }
 0129                    collection.Add(item);
 130                }
 131            }
 132
 0133            return collection;
 134        }
 135
 136        protected override void InsertItem(int index, XmlElement item)
 137        {
 100138            if (item == null)
 139            {
 0140                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item));
 141            }
 142
 100143            base.InsertItem(index, item);
 100144        }
 145
 146        protected override void SetItem(int index, XmlElement item)
 147        {
 0148            if (item == null)
 149            {
 0150                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(item));
 151            }
 152
 0153            base.SetItem(index, item);
 0154        }
 155    }
 156}