< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.TextEncoderDefaults
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Channels/TransportDefaults.cs
Line coverage
65%
Covered lines: 31
Uncovered lines: 16
Coverable lines: 47
Total lines: 147
Line coverage: 65.9%
Branch coverage
35%
Covered branches: 7
Total branches: 20
Branch coverage: 35%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
ValidateEncoding(...)50%4471.42%
EncodingToCharSet(...)83.33%6687.5%
TryGetEncoding(...)0%10100%
.ctor(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Channels/TransportDefaults.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.Text;
 6using System.Xml;
 7
 8namespace CoreWCF.Channels
 9{
 10    internal static class EncoderDefaults
 11    {
 12        internal const int MaxReadPoolSize = 64;
 13        internal const int MaxWritePoolSize = 16;
 14
 15        internal const int BufferedReadDefaultMaxDepth = 128;
 16        internal const int BufferedReadDefaultMaxStringContentLength = int.MaxValue;
 17        internal const int BufferedReadDefaultMaxArrayLength = int.MaxValue;
 18        internal const int BufferedReadDefaultMaxBytesPerRead = int.MaxValue;
 19        internal const int BufferedReadDefaultMaxNameTableCharCount = int.MaxValue;
 20
 21        internal static readonly XmlDictionaryReaderQuotas ReaderQuotas = new XmlDictionaryReaderQuotas();
 22
 23        internal static bool IsDefaultReaderQuotas(XmlDictionaryReaderQuotas quotas)
 24        {
 25            return quotas.ModifiedQuotas == 0x00;
 26        }
 27    }
 28
 29    internal static class TransportDefaults
 30    {
 31        internal const long MaxReceivedMessageSize = 65536;
 32        internal const int MaxBufferSize = (int)MaxReceivedMessageSize;
 33        internal const long MaxBufferPoolSize = 512 * 1024;
 34    }
 35
 36    internal static class HttpTransportDefaults
 37    {
 38        internal const TransferMode TransferMode = CoreWCF.TransferMode.Buffered;
 39        internal const string Realm = "";
 40    }
 41
 42    internal static class TextEncoderDefaults
 43    {
 244        public static readonly Encoding Encoding = Encoding.GetEncoding(EncodingString, new EncoderExceptionFallback(),
 245            new DecoderExceptionFallback());
 46
 47        internal const string EncodingString = "utf-8";
 48
 249        internal static readonly Encoding[] SupportedEncodings =
 250        {
 251            Encoding.UTF8, Encoding.Unicode,
 252            Encoding.BigEndianUnicode
 253        };
 54
 255        internal static readonly CharSetEncoding[] CharSetEncodings =
 256        {
 257            new CharSetEncoding("utf-8", Encoding.UTF8),
 258            new CharSetEncoding("utf-16LE", Encoding.Unicode),
 259            new CharSetEncoding("utf-16BE", Encoding.BigEndianUnicode),
 260            new CharSetEncoding("utf-16", null), // Ignore.  Ambiguous charSet, so autodetect.
 261            new CharSetEncoding(null, null), // CharSet omitted, so autodetect.
 262        };
 63
 64
 65        public static void ValidateEncoding(Encoding encoding)
 66        {
 11367            string charSet = encoding.WebName;
 11368            Encoding[] supportedEncodings = SupportedEncodings;
 22669            for (int i = 0; i < supportedEncodings.Length; i++)
 70            {
 11371                if (charSet == supportedEncodings[i].WebName)
 72                {
 11373                    return;
 74                }
 75            }
 76
 077            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 078                new ArgumentException(SR.Format(SR.MessageTextEncodingNotSupported, charSet), nameof(encoding)));
 79        }
 80
 81        public static string EncodingToCharSet(Encoding encoding)
 82        {
 14683            string webName = encoding.WebName;
 14684            CharSetEncoding[] charSetEncodings = CharSetEncodings;
 29885            for (int i = 0; i < charSetEncodings.Length; i++)
 86            {
 14987                Encoding enc = charSetEncodings[i]._encoding;
 14988                if (enc == null)
 89                {
 90                    continue;
 91                }
 92
 14993                if (enc.WebName == webName)
 94                {
 14695                    return charSetEncodings[i]._charSet;
 96                }
 97            }
 098            return null;
 99        }
 100
 101        public static bool TryGetEncoding(string charSet, out Encoding encoding)
 102        {
 0103            CharSetEncoding[] charSetEncodings = CharSetEncodings;
 104
 105            // Quick check for exact equality
 0106            for (int i = 0; i < charSetEncodings.Length; i++)
 107            {
 0108                if (charSetEncodings[i]._charSet == charSet)
 109                {
 0110                    encoding = charSetEncodings[i]._encoding;
 0111                    return true;
 112                }
 113            }
 114
 115            // Check for case insensitive match
 0116            for (int i = 0; i < charSetEncodings.Length; i++)
 117            {
 0118                string compare = charSetEncodings[i]._charSet;
 0119                if (compare == null)
 120                {
 121                    continue;
 122                }
 123
 0124                if (compare.Equals(charSet, StringComparison.OrdinalIgnoreCase))
 125                {
 0126                    encoding = charSetEncodings[i]._encoding;
 0127                    return true;
 128                }
 129            }
 130
 0131            encoding = null;
 0132            return false;
 133        }
 134
 135        internal class CharSetEncoding
 136        {
 137            internal string _charSet;
 138            internal Encoding _encoding;
 139
 10140            internal CharSetEncoding(string charSet, Encoding enc)
 141            {
 10142                _charSet = charSet;
 10143                _encoding = enc;
 10144            }
 145        }
 146    }
 147}