< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.TextMessageEncodingBindingElement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/TextMessageEncodingBindingElement.cs
Line coverage
59%
Covered lines: 51
Uncovered lines: 35
Coverable lines: 86
Total lines: 245
Line coverage: 59.3%
Branch coverage
27%
Covered branches: 12
Total branches: 44
Branch coverage: 27.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/TextMessageEncodingBindingElement.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;
 7using CoreWCF.Description;
 8
 9namespace CoreWCF.Channels
 10{
 11    public sealed class TextMessageEncodingBindingElement : MessageEncodingBindingElement, IWsdlExportExtension, IPolicy
 12    {
 13        private int _maxReadPoolSize;
 14        private int _maxWritePoolSize;
 15        private readonly XmlDictionaryReaderQuotas _readerQuotas;
 16        private MessageVersion _messageVersion;
 17        private Encoding _writeEncoding;
 18
 19        public TextMessageEncodingBindingElement()
 101620            : this(MessageVersion.Default, TextEncoderDefaults.Encoding)
 21        {
 101622        }
 23
 120624        public TextMessageEncodingBindingElement(MessageVersion messageVersion, Encoding writeEncoding)
 25        {
 120626            if (writeEncoding == null)
 27            {
 028                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writeEncoding));
 29            }
 30
 120631            TextEncoderDefaults.ValidateEncoding(writeEncoding);
 32
 120633            _maxReadPoolSize = EncoderDefaults.MaxReadPoolSize;
 120634            _maxWritePoolSize = EncoderDefaults.MaxWritePoolSize;
 120635            _readerQuotas = new XmlDictionaryReaderQuotas();
 120636            EncoderDefaults.ReaderQuotas.CopyTo(_readerQuotas);
 120637            _messageVersion = messageVersion ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(
 120638            _writeEncoding = writeEncoding;
 120639        }
 40
 41        private TextMessageEncodingBindingElement(TextMessageEncodingBindingElement elementToBeCloned)
 747142            : base(elementToBeCloned)
 43        {
 747144            _maxReadPoolSize = elementToBeCloned._maxReadPoolSize;
 747145            _maxWritePoolSize = elementToBeCloned._maxWritePoolSize;
 747146            _readerQuotas = new XmlDictionaryReaderQuotas();
 747147            elementToBeCloned._readerQuotas.CopyTo(_readerQuotas);
 747148            _writeEncoding = elementToBeCloned._writeEncoding;
 747149            _messageVersion = elementToBeCloned._messageVersion;
 747150        }
 51
 52        public int MaxReadPoolSize
 53        {
 54            get
 55            {
 77456                return _maxReadPoolSize;
 57            }
 58            set
 59            {
 860                if (value <= 0)
 61                {
 062                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 063                                                    SRCommon.ValueMustBePositive));
 64                }
 865                _maxReadPoolSize = value;
 866            }
 67        }
 68
 69        public int MaxWritePoolSize
 70        {
 71            get
 72            {
 77473                return _maxWritePoolSize;
 74            }
 75            set
 76            {
 877                if (value <= 0)
 78                {
 079                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 080                                                    SRCommon.ValueMustBePositive));
 81                }
 882                _maxWritePoolSize = value;
 883            }
 84        }
 85
 86        public XmlDictionaryReaderQuotas ReaderQuotas
 87        {
 88            get
 89            {
 464690                return _readerQuotas;
 91            }
 92            set
 93            {
 18494                if (value == null)
 95                {
 096                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 97                }
 98
 18499                value.CopyTo(_readerQuotas);
 184100            }
 101        }
 102
 103        public override MessageVersion MessageVersion
 104        {
 105            get
 106            {
 4647107                return _messageVersion;
 108            }
 109            set
 110            {
 593111                _messageVersion = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value
 593112            }
 113        }
 114
 115        public Encoding WriteEncoding
 116        {
 117            get
 118            {
 4628119                return _writeEncoding;
 120            }
 121            set
 122            {
 10123                if (value == null)
 124                {
 0125                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 126                }
 127
 10128                TextEncoderDefaults.ValidateEncoding(value);
 10129                _writeEncoding = value;
 10130            }
 131        }
 132
 133        public override BindingElement Clone()
 134        {
 7471135            return new TextMessageEncodingBindingElement(this);
 136        }
 137
 138        public override MessageEncoderFactory CreateMessageEncoderFactory()
 139        {
 770140            return new TextMessageEncoderFactory(MessageVersion, WriteEncoding, MaxReadPoolSize, MaxWritePoolSize, Reade
 141        }
 142
 143        public override T GetProperty<T>(BindingContext context)
 144        {
 5352145            if (context == null)
 146            {
 0147                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 148            }
 5352149            if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
 150            {
 49151                return (T)(object)_readerQuotas;
 152            }
 153            else
 154            {
 5303155                return base.GetProperty<T>(context);
 156            }
 157        }
 158
 159        void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context)
 160        {
 40161            if (context == null)
 162            {
 0163                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 164            }
 40165        }
 166
 0167        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext context) { }
 168
 169        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
 170        {
 31171            if (context == null)
 172            {
 0173                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 174            }
 175
 31176            SoapHelper.SetSoapVersion(context, exporter, MessageVersion.Envelope);
 31177        }
 178
 179        protected override bool CheckEncodingVersion(EnvelopeVersion version)
 180        {
 0181            return _messageVersion.Envelope == version;
 182        }
 183
 184        protected override bool IsMatch(BindingElement b)
 185        {
 0186            if (!base.IsMatch(b))
 187            {
 0188                return false;
 189            }
 190
 0191            if (!(b is TextMessageEncodingBindingElement text))
 192            {
 0193                return false;
 194            }
 195
 0196            if (_maxReadPoolSize != text.MaxReadPoolSize)
 197            {
 0198                return false;
 199            }
 200
 0201            if (_maxWritePoolSize != text.MaxWritePoolSize)
 202            {
 0203                return false;
 204            }
 205
 206            // compare XmlDictionaryReaderQuotas
 0207            if (_readerQuotas.MaxStringContentLength != text.ReaderQuotas.MaxStringContentLength)
 208            {
 0209                return false;
 210            }
 211
 0212            if (_readerQuotas.MaxArrayLength != text.ReaderQuotas.MaxArrayLength)
 213            {
 0214                return false;
 215            }
 216
 0217            if (_readerQuotas.MaxBytesPerRead != text.ReaderQuotas.MaxBytesPerRead)
 218            {
 0219                return false;
 220            }
 221
 0222            if (_readerQuotas.MaxDepth != text.ReaderQuotas.MaxDepth)
 223            {
 0224                return false;
 225            }
 226
 0227            if (_readerQuotas.MaxNameTableCharCount != text.ReaderQuotas.MaxNameTableCharCount)
 228            {
 0229                return false;
 230            }
 231
 0232            if (WriteEncoding.EncodingName != text.WriteEncoding.EncodingName)
 233            {
 0234                return false;
 235            }
 236
 0237            if (!MessageVersion.IsMatch(text.MessageVersion))
 238            {
 0239                return false;
 240            }
 241
 0242            return true;
 243        }
 244    }
 245}