< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.IdentityModelDictionary
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/IdentityModelDictionary.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 47
Coverable lines: 47
Total lines: 122
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
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%
CreateString(...)100%110%
TryLookup(...)0%880%
TryLookup(...)0%880%
TryLookup(...)0%12120%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/IdentityModelDictionary.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;
 7
 8namespace CoreWCF.IdentityModel
 9{
 10    internal class IdentityModelDictionary : IXmlDictionary
 11    {
 012        public static readonly IdentityModelDictionary Version1 = new IdentityModelDictionary(new IdentityModelStringsVe
 13        private readonly IdentityModelStrings _strings;
 14        private readonly int _count;
 15        private XmlDictionaryString[] _dictionaryStrings;
 16        private Dictionary<string, int> _dictionary;
 17        private XmlDictionaryString[] _versionedDictionaryStrings;
 18
 019        public IdentityModelDictionary(IdentityModelStrings strings)
 20        {
 021            _strings = strings;
 022            _count = strings.Count;
 023        }
 24
 25        public static IdentityModelDictionary CurrentVersion
 26        {
 27            get
 28            {
 029                return Version1;
 30            }
 31        }
 32
 33        public XmlDictionaryString CreateString(string value, int key)
 34        {
 035            return new XmlDictionaryString(this, value, key);
 36        }
 37
 38        public bool TryLookup(string key, out XmlDictionaryString value)
 39        {
 040            if (key == null)
 41            {
 042                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(key)));
 43            }
 44
 045            if (_dictionary == null)
 46            {
 047                Dictionary<string, int> dictionary = new Dictionary<string, int>(_count);
 048                for (int i = 0; i < _count; i++)
 49                {
 050                    dictionary.Add(_strings[i], i);
 51                }
 52
 053                _dictionary = dictionary;
 54            }
 055            if (_dictionary.TryGetValue(key, out int id))
 56            {
 057                return TryLookup(id, out value);
 58            }
 59
 060            value = null;
 061            return false;
 62        }
 63
 64        public bool TryLookup(int key, out XmlDictionaryString value)
 65        {
 066            if (key < 0 || key >= _count)
 67            {
 068                value = null;
 069                return false;
 70            }
 071            if (_dictionaryStrings == null)
 72            {
 073                _dictionaryStrings = new XmlDictionaryString[_count];
 74            }
 75
 076            XmlDictionaryString s = _dictionaryStrings[key];
 077            if (s == null)
 78            {
 079                s = CreateString(_strings[key], key);
 080                _dictionaryStrings[key] = s;
 81            }
 082            value = s;
 083            return true;
 84        }
 85
 86        public bool TryLookup(XmlDictionaryString key, out XmlDictionaryString value)
 87        {
 088            if (key == null)
 89            {
 090                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(key)));
 91            }
 92
 093            if (key.Dictionary == this)
 94            {
 095                value = key;
 096                return true;
 97            }
 098            if (key.Dictionary == CurrentVersion)
 99            {
 0100                if (_versionedDictionaryStrings == null)
 101                {
 0102                    _versionedDictionaryStrings = new XmlDictionaryString[CurrentVersion._count];
 103                }
 104
 0105                XmlDictionaryString s = _versionedDictionaryStrings[key.Key];
 0106                if (s == null)
 107                {
 0108                    if (!TryLookup(key.Value, out s))
 109                    {
 0110                        value = null;
 0111                        return false;
 112                    }
 0113                    _versionedDictionaryStrings[key.Key] = s;
 114                }
 0115                value = s;
 0116                return true;
 117            }
 0118            value = null;
 0119            return false;
 120        }
 121    }
 122}