< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.EncoderDefaults
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Channels/TransportDefaults.cs
Line coverage
50%
Covered lines: 1
Uncovered lines: 1
Coverable lines: 2
Total lines: 147
Line coverage: 50%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
IsDefaultReaderQuotas(...)100%110%

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
 221        internal static readonly XmlDictionaryReaderQuotas ReaderQuotas = new XmlDictionaryReaderQuotas();
 22
 23        internal static bool IsDefaultReaderQuotas(XmlDictionaryReaderQuotas quotas)
 24        {
 025            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    {
 44        public static readonly Encoding Encoding = Encoding.GetEncoding(EncodingString, new EncoderExceptionFallback(),
 45            new DecoderExceptionFallback());
 46
 47        internal const string EncodingString = "utf-8";
 48
 49        internal static readonly Encoding[] SupportedEncodings =
 50        {
 51            Encoding.UTF8, Encoding.Unicode,
 52            Encoding.BigEndianUnicode
 53        };
 54
 55        internal static readonly CharSetEncoding[] CharSetEncodings =
 56        {
 57            new CharSetEncoding("utf-8", Encoding.UTF8),
 58            new CharSetEncoding("utf-16LE", Encoding.Unicode),
 59            new CharSetEncoding("utf-16BE", Encoding.BigEndianUnicode),
 60            new CharSetEncoding("utf-16", null), // Ignore.  Ambiguous charSet, so autodetect.
 61            new CharSetEncoding(null, null), // CharSet omitted, so autodetect.
 62        };
 63
 64
 65        public static void ValidateEncoding(Encoding encoding)
 66        {
 67            string charSet = encoding.WebName;
 68            Encoding[] supportedEncodings = SupportedEncodings;
 69            for (int i = 0; i < supportedEncodings.Length; i++)
 70            {
 71                if (charSet == supportedEncodings[i].WebName)
 72                {
 73                    return;
 74                }
 75            }
 76
 77            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 78                new ArgumentException(SR.Format(SR.MessageTextEncodingNotSupported, charSet), nameof(encoding)));
 79        }
 80
 81        public static string EncodingToCharSet(Encoding encoding)
 82        {
 83            string webName = encoding.WebName;
 84            CharSetEncoding[] charSetEncodings = CharSetEncodings;
 85            for (int i = 0; i < charSetEncodings.Length; i++)
 86            {
 87                Encoding enc = charSetEncodings[i]._encoding;
 88                if (enc == null)
 89                {
 90                    continue;
 91                }
 92
 93                if (enc.WebName == webName)
 94                {
 95                    return charSetEncodings[i]._charSet;
 96                }
 97            }
 98            return null;
 99        }
 100
 101        public static bool TryGetEncoding(string charSet, out Encoding encoding)
 102        {
 103            CharSetEncoding[] charSetEncodings = CharSetEncodings;
 104
 105            // Quick check for exact equality
 106            for (int i = 0; i < charSetEncodings.Length; i++)
 107            {
 108                if (charSetEncodings[i]._charSet == charSet)
 109                {
 110                    encoding = charSetEncodings[i]._encoding;
 111                    return true;
 112                }
 113            }
 114
 115            // Check for case insensitive match
 116            for (int i = 0; i < charSetEncodings.Length; i++)
 117            {
 118                string compare = charSetEncodings[i]._charSet;
 119                if (compare == null)
 120                {
 121                    continue;
 122                }
 123
 124                if (compare.Equals(charSet, StringComparison.OrdinalIgnoreCase))
 125                {
 126                    encoding = charSetEncodings[i]._encoding;
 127                    return true;
 128                }
 129            }
 130
 131            encoding = null;
 132            return false;
 133        }
 134
 135        internal class CharSetEncoding
 136        {
 137            internal string _charSet;
 138            internal Encoding _encoding;
 139
 140            internal CharSetEncoding(string charSet, Encoding enc)
 141            {
 142                _charSet = charSet;
 143                _encoding = enc;
 144            }
 145        }
 146    }
 147}