< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.TransportBindingElement
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/TransportBindingElement.cs
Line coverage
78%
Covered lines: 57
Uncovered lines: 16
Coverable lines: 73
Total lines: 202
Line coverage: 78%
Branch coverage
69%
Covered branches: 29
Total branches: 42
Branch coverage: 69%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)100%11100%
GetProperty(...)83.33%181884.21%
GetProtectionRequirements(...)100%11100%
GetProtectionRequirements(...)100%22100%
ExportWsdlEndpoint(...)80%101081.81%
IsMatch(...)0%880%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/TransportBindingElement.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.ObjectModel;
 6using System.Xml;
 7using CoreWCF.Description;
 8using CoreWCF.Security;
 9using WsdlNS = System.Web.Services.Description;
 10
 11namespace CoreWCF.Channels
 12{
 13    public abstract class TransportBindingElement : BindingElement
 14    {
 15        private bool _manualAddressing;
 16        private long _maxBufferPoolSize;
 17        private long _maxReceivedMessageSize;
 18
 165219        protected TransportBindingElement()
 20        {
 165221            _manualAddressing = TransportDefaults.ManualAddressing;
 165222            _maxBufferPoolSize = TransportDefaults.MaxBufferPoolSize;
 165223            _maxReceivedMessageSize = TransportDefaults.MaxReceivedMessageSize;
 165224        }
 25
 1025926        protected TransportBindingElement(TransportBindingElement elementToBeCloned)
 27        {
 1025928            _manualAddressing = elementToBeCloned._manualAddressing;
 1025929            _maxBufferPoolSize = elementToBeCloned._maxBufferPoolSize;
 1025930            _maxReceivedMessageSize = elementToBeCloned._maxReceivedMessageSize;
 1025931        }
 32
 33        [System.ComponentModel.DefaultValueAttribute(false)]
 34        public virtual bool ManualAddressing
 35        {
 36            get
 37            {
 117838                return _manualAddressing;
 39            }
 40
 41            set
 42            {
 8443                _manualAddressing = value;
 8444            }
 45        }
 46
 47        public virtual long MaxBufferPoolSize
 48        {
 49            get
 50            {
 53351                return _maxBufferPoolSize;
 52            }
 53            set
 54            {
 2355                if (value < 0)
 56                {
 057                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 058                        SRCommon.ValueMustBeNonNegative));
 59                }
 2360                _maxBufferPoolSize = value;
 2361            }
 62        }
 63
 64        [System.ComponentModel.DefaultValueAttribute((long)65536)]
 65        public virtual long MaxReceivedMessageSize
 66        {
 67            get
 68            {
 344169                return _maxReceivedMessageSize;
 70            }
 71            set
 72            {
 6973                if (value <= 0)
 74                {
 075                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 076                        SRCommon.ValueMustBePositive));
 77                }
 6978                _maxReceivedMessageSize = value;
 6979            }
 80        }
 81
 82        public abstract string Scheme { get; }
 83
 84        public override T GetProperty<T>(BindingContext context)
 85        {
 115486            if (context == null)
 87            {
 088                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context));
 89            }
 90
 115491            if (typeof(T) == typeof(ChannelProtectionRequirements))
 92            {
 993                ChannelProtectionRequirements myRequirements = GetProtectionRequirements(context);
 994                myRequirements.Add(context.GetInnerProperty<ChannelProtectionRequirements>() ?? new ChannelProtectionReq
 995                return (T)(object)myRequirements;
 96            }
 97
 98            // to cover all our bases, let's iterate through the BindingParameters to make sure
 99            // we haven't missed a query (since we're the Transport and we're at the bottom)
 1145100            Collection<BindingElement> bindingElements = new Collection<BindingElement>();
 3480101            foreach (object param in context.BindingParameters)
 102            {
 595103                if (param is BindingElement element)
 104                {
 375105                    bindingElements.Add(element);
 106                }
 107            }
 108
 3038109            for (int i = 0; i < bindingElements.Count; i++)
 110            {
 375111                T result = bindingElements[i].GetIndividualProperty<T>();
 375112                if (result != default(T))
 113                {
 1114                    return result;
 115                }
 116            }
 117
 1144118            if (typeof(T) == typeof(MessageVersion))
 119            {
 227120                return (T)(object)TransportDefaults.GetDefaultMessageEncoderFactory().MessageVersion;
 121            }
 122
 917123            if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
 124            {
 6125                return (T)(object)new XmlDictionaryReaderQuotas();
 126            }
 127
 911128            return null;
 129        }
 130
 131        private ChannelProtectionRequirements GetProtectionRequirements(AddressingVersion addressingVersion)
 132        {
 9133            ChannelProtectionRequirements result = new ChannelProtectionRequirements();
 9134            result.IncomingSignatureParts.AddParts(addressingVersion.SignedMessageParts);
 9135            result.OutgoingSignatureParts.AddParts(addressingVersion.SignedMessageParts);
 9136            return result;
 137        }
 138
 139        internal ChannelProtectionRequirements GetProtectionRequirements(BindingContext context)
 140        {
 9141            AddressingVersion addressingVersion = AddressingVersion.WSAddressing10;
 9142            MessageEncodingBindingElement messageEncoderBindingElement = context.Binding.Elements.Find<MessageEncodingBi
 9143            if (messageEncoderBindingElement != null)
 144            {
 9145                addressingVersion = messageEncoderBindingElement.MessageVersion.Addressing;
 146            }
 147
 9148            return GetProtectionRequirements(addressingVersion);
 149        }
 150
 151        public static void ExportWsdlEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext,
 152            string wsdlTransportUri, EndpointAddress address, AddressingVersion addressingVersion)
 153        {
 32154            if (exporter == null)
 155            {
 0156                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter));
 157            }
 158
 32159            if (endpointContext == null)
 160            {
 0161                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpointContext));
 162            }
 163
 164            // Set SoapBinding Transport URI
 32165            if (wsdlTransportUri != null)
 166            {
 32167                WsdlNS.SoapBinding soapBinding = SoapHelper.GetOrCreateSoapBinding(endpointContext, exporter);
 168
 32169                if (soapBinding != null)
 170                {
 32171                    soapBinding.Transport = wsdlTransportUri;
 172                }
 173            }
 174
 32175            if (endpointContext.WsdlPort != null)
 176            {
 32177                WsdlExporter.WSAddressingHelper.AddAddressToWsdlPort(endpointContext.WsdlPort, address, addressingVersio
 178            }
 32179        }
 180
 181        protected override bool IsMatch(BindingElement b)
 182        {
 0183            if (b == null)
 184            {
 0185                return false;
 186            }
 0187            if (!(b is TransportBindingElement transport))
 188            {
 0189                return false;
 190            }
 0191            if (_maxBufferPoolSize != transport.MaxBufferPoolSize)
 192            {
 0193                return false;
 194            }
 0195            if (_maxReceivedMessageSize != transport.MaxReceivedMessageSize)
 196            {
 0197                return false;
 198            }
 0199            return true;
 200        }
 201    }
 202}