< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.IdentityModel.CanonicalizationDriver
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/CanonicalizationDriver.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 45
Coverable lines: 45
Total lines: 106
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetInclusivePrefixes()100%110%
Reset()100%110%
SetInclusivePrefixes(...)100%110%
SetInput(...)0%220%
SetInput(...)0%220%
GetBytes()100%110%
GetMemoryStream()100%110%
WriteTo(...)100%110%
WriteTo(...)0%16160%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/IdentityModel/CanonicalizationDriver.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.IO;
 6using System.Security.Cryptography;
 7using System.Xml;
 8
 9namespace CoreWCF.IdentityModel
 10{
 11    internal sealed class CanonicalizationDriver
 12    {
 13        private XmlReader _reader;
 14        private string[] _inclusivePrefixes;
 15
 016        public bool CloseReadersAfterProcessing { get; set; }
 17
 018        public bool IncludeComments { get; set; }
 19
 20        public string[] GetInclusivePrefixes()
 21        {
 022            return _inclusivePrefixes;
 23        }
 24
 25        public void Reset()
 26        {
 027            _reader = (XmlReader)null;
 028        }
 29
 30        public void SetInclusivePrefixes(string[] inclusivePrefixes)
 31        {
 032            _inclusivePrefixes = inclusivePrefixes;
 033        }
 34
 35        public void SetInput(Stream stream)
 36        {
 037            if (stream == null)
 038                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(stream));
 039            _reader = XmlReader.Create(stream);
 040        }
 41
 42        public void SetInput(XmlReader reader)
 43        {
 044            _reader = reader ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 045        }
 46
 47        public byte[] GetBytes()
 48        {
 049            return GetMemoryStream().ToArray();
 50        }
 51
 52        public MemoryStream GetMemoryStream()
 53        {
 054            MemoryStream memoryStream = new MemoryStream();
 055            WriteTo((Stream)memoryStream);
 056            memoryStream.Seek(0L, SeekOrigin.Begin);
 057            return memoryStream;
 58        }
 59
 60        public void WriteTo(HashAlgorithm hashAlgorithm)
 61        {
 062            WriteTo((Stream)new HashStream(hashAlgorithm));
 063        }
 64
 65        public void WriteTo(Stream canonicalStream)
 66        {
 067            if (_reader == null)
 068                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError((Exception)new InvalidOperationException(SR.Fo
 069            if (_reader is XmlDictionaryReader reader && reader.CanCanonicalize)
 70            {
 071                _ = (int)reader.MoveToContent();
 072                reader.StartCanonicalization(canonicalStream, IncludeComments, _inclusivePrefixes);
 073                reader.Skip();
 074                reader.EndCanonicalization();
 75            }
 76            else
 77            {
 078                XmlDictionaryWriter textWriter = XmlDictionaryWriter.CreateTextWriter(Stream.Null);
 079                if (_inclusivePrefixes != null)
 80                {
 081                    textWriter.WriteStartElement("a", _reader.LookupNamespace(string.Empty));
 082                    for (int index = 0; index < _inclusivePrefixes.Length; ++index)
 83                    {
 084                        string namespaceUri = _reader.LookupNamespace(_inclusivePrefixes[index]);
 085                        if (namespaceUri != null)
 086                            textWriter.WriteXmlnsAttribute(_inclusivePrefixes[index], namespaceUri);
 87                    }
 88                }
 089                textWriter.StartCanonicalization(canonicalStream, IncludeComments, _inclusivePrefixes);
 90                //TODO check the use of wrappedreader
 91                // if (this.reader is WrappedReader)
 92                //  ((WrappedReader) this.reader).XmlTokens.GetWriter().WriteTo(textWriter, new DictionaryManager());
 93                // else
 094                textWriter.WriteNode(_reader, false);
 095                textWriter.Flush();
 096                textWriter.EndCanonicalization();
 097                if (_inclusivePrefixes != null)
 098                    textWriter.WriteEndElement();
 099                textWriter.Close();
 100            }
 0101            if (CloseReadersAfterProcessing)
 0102                _reader.Close();
 0103            _reader = (XmlReader)null;
 0104        }
 105    }
 106}