< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Security.ReferenceList
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/ReferenceList.cs
Line coverage
6%
Covered lines: 3
Uncovered lines: 45
Coverable lines: 48
Total lines: 125
Line coverage: 6.2%
Branch coverage
0%
Covered branches: 0
Total branches: 16
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%11100%
.ctor()100%110%
AddReferredId(...)0%220%
ContainsReferredId(...)0%220%
GetReferredId(...)100%110%
ReadFrom(...)0%660%
TryRemoveReferredId(...)0%220%
WriteTo(...)0%440%
.cctor()100%110%
ReadFrom(...)100%110%
WriteTo(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/ReferenceList.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.Xml;
 7using DictionaryManager = CoreWCF.IdentityModel.DictionaryManager;
 8using ISecurityElement = CoreWCF.IdentityModel.ISecurityElement;
 9
 10namespace CoreWCF.Security
 11{
 12    internal sealed class ReferenceList : ISecurityElement
 13    {
 214        internal static readonly XmlDictionaryString ElementName = XD.XmlEncryptionDictionary.ReferenceList;
 15        private const string NamespacePrefix = XmlEncryptionStrings.Prefix;
 216        internal static readonly XmlDictionaryString NamespaceUri = XD.XmlEncryptionDictionary.Namespace;// EncryptedTyp
 217        internal static readonly XmlDictionaryString UriAttribute = XD.XmlEncryptionDictionary.URI;
 018        private readonly List<string> _referredIds = new List<string>();
 19
 020        public ReferenceList()
 21        {
 022        }
 23
 024        public int DataReferenceCount => _referredIds.Count;
 25
 026        public bool HasId => false;
 27
 028        public string Id => throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
 29
 30        public void AddReferredId(string id)
 31        {
 032            if (id == null)
 33            {
 034                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(id)));
 35            }
 036            _referredIds.Add(id);
 037        }
 38
 39        public bool ContainsReferredId(string id)
 40        {
 041            if (id == null)
 42            {
 043                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(id)));
 44            }
 045            return _referredIds.Contains(id);
 46        }
 47
 48        public string GetReferredId(int index)
 49        {
 050            return _referredIds[index];
 51        }
 52
 53        public void ReadFrom(XmlDictionaryReader reader)
 54        {
 055            reader.ReadStartElement(ElementName, NamespaceUri);
 056            while (reader.IsStartElement())
 57            {
 058                string id = DataReference.ReadFrom(reader);
 059                if (_referredIds.Contains(id))
 60                {
 061                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 062                        new Exception(SR.Format("InvalidDataReferenceInReferenceList", "#" + id)));
 63                }
 064                _referredIds.Add(id);
 65            }
 066            reader.ReadEndElement(); // ReferenceList
 067            if (DataReferenceCount == 0)
 68            {
 069                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Exception(SR.Format("ReferenceListCannotBe
 70            }
 071        }
 72
 73        public bool TryRemoveReferredId(string id)
 74        {
 075            if (id == null)
 76            {
 077                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(id)));
 78            }
 079            return _referredIds.Remove(id);
 80        }
 81
 82        public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 83        {
 084            if (DataReferenceCount == 0)
 85            {
 086                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format("Refer
 87            }
 088            writer.WriteStartElement(NamespacePrefix, ElementName, NamespaceUri);
 089            for (int i = 0; i < DataReferenceCount; i++)
 90            {
 091                DataReference.WriteTo(writer, _referredIds[i]);
 92            }
 093            writer.WriteEndElement(); // ReferenceList
 094        }
 95
 96        private static class DataReference
 97        {
 098            internal static readonly XmlDictionaryString ElementName = XD.XmlEncryptionDictionary.DataReference;
 099            internal static readonly XmlDictionaryString NamespaceUri = XD.XmlEncryptionDictionary.Namespace;
 100
 101            public static string ReadFrom(XmlDictionaryReader reader)
 102            {
 0103                throw new NotImplementedException();
 104                //string prefix;
 105                //string uri = XmlHelper.ReadEmptyElementAndRequiredAttribute(reader, ElementName, NamespaceUri, Referen
 106                //if (uri.Length < 2 || uri[0] != '#')
 107                //{
 108                //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 109                //        new SecurityMessageSerializationException(SR.GetString(SR.InvalidDataReferenceInReferenceList,
 110                //}
 111                //return uri.Substring(1);
 112            }
 113
 114            public static void WriteTo(XmlDictionaryWriter writer, string referredId)
 115            {
 0116                writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, ElementName, NamespaceUri);
 0117                writer.WriteStartAttribute(UriAttribute, null);
 0118                writer.WriteString("#");
 0119                writer.WriteString(referredId);
 0120                writer.WriteEndAttribute();
 0121                writer.WriteEndElement();
 0122            }
 123        }
 124    }
 125}