< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.XmlAttributeHolder
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/XmlAttributeHolder.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 49
Coverable lines: 49
Total lines: 110
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
.ctor(...)100%110%
WriteTo(...)100%110%
WriteAttributes(...)0%220%
ReadAttributes(...)100%110%
ReadAttributes(...)0%880%
Deduct(...)0%220%
GetAttribute(...)0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/XmlAttributeHolder.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.Xml;
 6
 7namespace CoreWCF.IdentityModel
 8{
 9    internal struct XmlAttributeHolder
 10    {
 011        public static XmlAttributeHolder[] emptyArray = Array.Empty<XmlAttributeHolder>();
 12
 13        public XmlAttributeHolder(string prefix, string localName, string ns, string value)
 14        {
 015            Prefix = prefix;
 016            LocalName = localName;
 017            NamespaceUri = ns;
 018            Value = value;
 019        }
 20
 021        public string Prefix { get; }
 22
 023        public string NamespaceUri { get; }
 24
 025        public string LocalName { get; }
 26
 027        public string Value { get; }
 28
 29        public void WriteTo(XmlWriter writer)
 30        {
 031            writer.WriteStartAttribute(Prefix, LocalName, NamespaceUri);
 032            writer.WriteString(Value);
 033            writer.WriteEndAttribute();
 034        }
 35
 36        public static void WriteAttributes(XmlAttributeHolder[] attributes, XmlWriter writer)
 37        {
 038            for (int i = 0; i < attributes.Length; i++)
 39            {
 040                attributes[i].WriteTo(writer);
 41            }
 042        }
 43
 44        public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader)
 45        {
 046            int maxSizeOfHeaders = int.MaxValue;
 047            return ReadAttributes(reader, ref maxSizeOfHeaders);
 48        }
 49
 50        public static XmlAttributeHolder[] ReadAttributes(XmlDictionaryReader reader, ref int maxSizeOfHeaders)
 51        {
 052            if (reader.AttributeCount == 0)
 53            {
 054                return emptyArray;
 55            }
 56
 057            XmlAttributeHolder[] attributes = new XmlAttributeHolder[reader.AttributeCount];
 058            reader.MoveToFirstAttribute();
 059            for (int i = 0; i < attributes.Length; i++)
 60            {
 061                string ns = reader.NamespaceURI;
 062                string localName = reader.LocalName;
 063                string prefix = reader.Prefix;
 064                string value = string.Empty;
 065                while (reader.ReadAttributeValue())
 66                {
 067                    if (value.Length == 0)
 68                    {
 069                        value = reader.Value;
 70                    }
 71                    else
 72                    {
 073                        value += reader.Value;
 74                    }
 75                }
 076                Deduct(prefix, ref maxSizeOfHeaders);
 077                Deduct(localName, ref maxSizeOfHeaders);
 078                Deduct(ns, ref maxSizeOfHeaders);
 079                Deduct(value, ref maxSizeOfHeaders);
 080                attributes[i] = new XmlAttributeHolder(prefix, localName, ns, value);
 081                reader.MoveToNextAttribute();
 82            }
 083            reader.MoveToElement();
 084            return attributes;
 85        }
 86
 87        private static void Deduct(string s, ref int maxSizeOfHeaders)
 88        {
 089            int byteCount = s.Length * sizeof(char);
 090            if (byteCount > maxSizeOfHeaders)
 91            {
 092                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRCommon.XmlBuff
 93            }
 094            maxSizeOfHeaders -= byteCount;
 095        }
 96
 97        public static string GetAttribute(XmlAttributeHolder[] attributes, string localName, string ns)
 98        {
 099            for (int i = 0; i < attributes.Length; i++)
 100            {
 0101                if (attributes[i].LocalName == localName && attributes[i].NamespaceUri == ns)
 102                {
 0103                    return attributes[i].Value;
 104                }
 105            }
 106
 0107            return null;
 108        }
 109    }
 110}