< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.NetTcpBinding
Assembly: CoreWCF.NetTcp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/NetTcpBinding.cs
Line coverage
86%
Covered lines: 46
Uncovered lines: 7
Coverable lines: 53
Total lines: 160
Line coverage: 86.7%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
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%
CreateMessageSecurity()100%44100%
Initialize()100%11100%
CreateBindingElements()100%44100%
CreateTransportSecurity()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/NetTcpBinding.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.ComponentModel;
 5using System.Xml;
 6using CoreWCF.Channels;
 7
 8namespace CoreWCF
 9{
 10    public class NetTcpBinding : Binding
 11    {
 12        // private BindingElements
 13        private TcpTransportBindingElement _transport;
 14        private BinaryMessageEncodingBindingElement _encoding;
 11615        private NetTcpSecurity _security = new NetTcpSecurity();
 16
 34817        public NetTcpBinding() { Initialize(); }
 18        public NetTcpBinding(SecurityMode securityMode)
 7519            : this()
 20        {
 7521            _security.Mode = securityMode;
 7522        }
 23
 24        public TransferMode TransferMode
 25        {
 226            get { return _transport.TransferMode; }
 9827            set { _transport.TransferMode = value; }
 28        }
 29
 30        public HostNameComparisonMode HostNameComparisonMode
 31        {
 032            get { return _transport.HostNameComparisonMode; }
 1833            set { _transport.HostNameComparisonMode = value; }
 34        }
 35
 36        [DefaultValue(TransportDefaults.MaxBufferPoolSize)]
 37        public long MaxBufferPoolSize
 38        {
 039            get { return _transport.MaxBufferPoolSize; }
 40            set
 41            {
 942                _transport.MaxBufferPoolSize = value;
 943            }
 44        }
 45
 46        public int MaxBufferSize
 47        {
 248            get { return _transport.MaxBufferSize; }
 1849            set { _transport.MaxBufferSize = value; }
 50        }
 51
 52        public int MaxConnections
 53        {
 054            get { return _transport.MaxPendingConnections; }
 55            set
 56            {
 957                _transport.MaxPendingConnections = value;
 958            }
 59        }
 60
 61        public int ListenBacklog
 62        {
 063            get { return _transport.ListenBacklog; }
 064            set { _transport.ListenBacklog = value; }
 65        }
 66
 67        public long MaxReceivedMessageSize
 68        {
 569            get { return _transport.MaxReceivedMessageSize; }
 2070            set { _transport.MaxReceivedMessageSize = value; }
 71        }
 72
 73        public XmlDictionaryReaderQuotas ReaderQuotas
 74        {
 175            get { return _encoding.ReaderQuotas; }
 76            set
 77            {
 978                if (value == null)
 79                {
 080                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 81                }
 82
 983                value.CopyTo(_encoding.ReaderQuotas);
 984            }
 85        }
 86
 87        //TODO: Work out if we want IBindingRuntimePreferences. Probably not as we're aiming for 100% async here
 88        //bool IBindingRuntimePreferences.ReceiveSynchronously
 89        //{
 90        //    get { return false; }
 91        //}
 92
 15393        public override string Scheme { get { return _transport.Scheme; } }
 94
 95        public EnvelopeVersion EnvelopeVersion
 96        {
 097            get { return EnvelopeVersion.Soap12; }
 98        }
 99
 100        internal SecurityBindingElement CreateMessageSecurity()
 101        {
 1122102            if (Security.Mode == SecurityMode.Message || Security.Mode == SecurityMode.TransportWithMessageCredential)
 103            {
 37104                return Security.CreateMessageSecurity(false);//ReliableSession.Enabled);
 105            }
 106            else
 107            {
 1085108                return null;
 109            }
 110        }
 111
 112        public NetTcpSecurity Security
 113        {
 2320114            get { return _security; }
 115            set
 116            {
 1117                _security = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 1118            }
 119        }
 120
 121        private void Initialize()
 122        {
 116123            _transport = new TcpTransportBindingElement();
 116124            _encoding = new BinaryMessageEncodingBindingElement();
 116125        }
 126
 127        public override BindingElementCollection CreateBindingElements()
 128        {
 129            // return collection of BindingElements
 1122130            BindingElementCollection bindingElements = new BindingElementCollection
 1122131            {
 1122132                // order of BindingElements is important
 1122133                // add encoding
 1122134                _encoding
 1122135            };
 1122136            SecurityBindingElement wsSecurity = CreateMessageSecurity();
 1122137            if (wsSecurity != null)
 138            {
 37139                bindingElements.Add(wsSecurity);
 140            }
 141            // add transport security
 1122142            BindingElement transportSecurity = CreateTransportSecurity();
 1122143            if (transportSecurity != null)
 144            {
 209145                bindingElements.Add(transportSecurity);
 146            }
 147            // TODO: Add ExtendedProtectionPolicy
 1122148            _transport.ExtendedProtectionPolicy = _security.Transport.ExtendedProtectionPolicy;
 149            // add transport (tcp)
 1122150            bindingElements.Add(_transport);
 151
 1122152            return bindingElements.Clone();
 153        }
 154
 155        private BindingElement CreateTransportSecurity()
 156        {
 1122157            return _security.CreateTransportSecurity();
 158        }
 159    }
 160}