< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.WebSocketTransportSettings
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/WebSocketTransportSettings.cs
Line coverage
62%
Covered lines: 47
Uncovered lines: 28
Coverable lines: 75
Total lines: 197
Line coverage: 62.6%
Branch coverage
47%
Covered branches: 16
Total branches: 34
Branch coverage: 47%
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%
Equals(...)50%121287.5%
Equals(...)0%220%
GetHashCode()0%220%
Clone()100%11100%
GetEffectiveKeepAliveInterval()50%22100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/Channels/WebSocketTransportSettings.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.Net.WebSockets;
 6using System.Threading;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF.Channels
 10{
 11    public sealed class WebSocketTransportSettings : IEquatable<WebSocketTransportSettings>
 12    {
 13        public const string ConnectionOpenedAction = "http://schemas.microsoft.com/2011/02/session/onopen";
 14        public const string BinaryMessageReceivedAction = "http://schemas.microsoft.com/2011/02/websockets/onbinarymessa
 15        public const string TextMessageReceivedAction = "http://schemas.microsoft.com/2011/02/websockets/ontextmessage";
 16        public const string SoapContentTypeHeader = "soap-content-type";
 17        public const string BinaryEncoderTransferModeHeader = "microsoft-binary-transfer-mode";
 18        internal const string WebSocketMethod = "WEBSOCKET";
 19        internal const string SoapSubProtocol = "soap";
 20        internal const string TransportUsageMethodName = "TransportUsage";
 21        private WebSocketTransportUsage _transportUsage;
 22        private TimeSpan _keepAliveInterval;
 23        private string _subProtocol;
 24        private int _maxPendingConnections;
 25
 87426        public WebSocketTransportSettings()
 27        {
 87428            _transportUsage = WebSocketDefaults.TransportUsage;
 87429            CreateNotificationOnConnection = WebSocketDefaults.CreateNotificationOnConnection;
 87430            _keepAliveInterval = WebSocketDefaults.DefaultKeepAliveInterval;
 87431            _subProtocol = WebSocketDefaults.SubProtocol;
 87432            DisablePayloadMasking = WebSocketDefaults.DisablePayloadMasking;
 87433            _maxPendingConnections = WebSocketDefaults.DefaultMaxPendingConnections;
 87434        }
 35
 876836        private WebSocketTransportSettings(WebSocketTransportSettings settings)
 37        {
 38            Fx.Assert(settings != null, "settings should not be null.");
 876839            TransportUsage = settings.TransportUsage;
 876840            SubProtocol = settings.SubProtocol;
 876841            KeepAliveInterval = settings.KeepAliveInterval;
 876842            DisablePayloadMasking = settings.DisablePayloadMasking;
 876843            CreateNotificationOnConnection = settings.CreateNotificationOnConnection;
 876844            MaxPendingConnections = settings.MaxPendingConnections;
 876845        }
 46
 47        public WebSocketTransportUsage TransportUsage
 48        {
 49            get
 50            {
 1055351                return _transportUsage;
 52            }
 53
 54            set
 55            {
 880956                WebSocketTransportUsageHelper.Validate(value);
 880957                _transportUsage = value;
 880958            }
 59        }
 60
 1843261        public bool CreateNotificationOnConnection { get; set; }
 62
 63        public TimeSpan KeepAliveInterval
 64        {
 65            get
 66            {
 877267                return _keepAliveInterval;
 68            }
 69
 70            set
 71            {
 877472                if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan)
 73                {
 074                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(
 075                                nameof(value),
 076                                value,
 077                                SRCommon.SFxTimeoutOutOfRange0));
 78                }
 79
 877480                if (TimeoutHelper.IsTooLarge(value))
 81                {
 082                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(
 083                                            nameof(value),
 084                                            value,
 085                                            SRCommon.SFxTimeoutOutOfRangeTooBig));
 86                }
 87
 877488                _keepAliveInterval = value;
 877489            }
 90        }
 91
 92        public string SubProtocol
 93        {
 94            get
 95            {
 878396                return _subProtocol;
 97            }
 98
 99            set
 100            {
 8800101                if (value != null)
 102                {
 473103                    if (value == string.Empty)
 104                    {
 0105                        throw Fx.Exception.Argument(nameof(value), SR.WebSocketInvalidProtocolEmptySubprotocolString);
 106                    }
 107
 473108                    if (value.Split(WebSocketHelper.ProtocolSeparators).Length > 1)
 109                    {
 0110                        throw Fx.Exception.Argument(nameof(value), SR.Format(SR.WebSocketInvalidProtocolContainsMultiple
 111                    }
 112
 473113                    if (WebSocketHelper.IsSubProtocolInvalid(value, out string invalidChar))
 114                    {
 0115                        throw Fx.Exception.Argument(nameof(value), SR.Format(SR.WebSocketInvalidProtocolInvalidCharInPro
 116                    }
 117                }
 118
 8800119                _subProtocol = value;
 8800120            }
 121        }
 122
 18420123        public bool DisablePayloadMasking { get; set; }
 124
 125        public int MaxPendingConnections
 126        {
 127            get
 128            {
 8772129                return _maxPendingConnections;
 130            }
 131
 132            set
 133            {
 8774134                if (value < 0)
 135                {
 0136                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(
 0137                        nameof(value),
 0138                        value,
 0139                        SRCommon.ValueMustBePositive));
 140                }
 141
 8774142                _maxPendingConnections = value;
 8774143            }
 144        }
 145
 146        public bool Equals(WebSocketTransportSettings other)
 147        {
 2148            if (other == null)
 149            {
 0150                return false;
 151            }
 152
 2153            return TransportUsage == other.TransportUsage
 2154                && CreateNotificationOnConnection == other.CreateNotificationOnConnection
 2155                && KeepAliveInterval == other.KeepAliveInterval
 2156                && DisablePayloadMasking == other.DisablePayloadMasking
 2157                && StringComparer.OrdinalIgnoreCase.Compare(SubProtocol, other.SubProtocol) == 0
 2158                && MaxPendingConnections == other.MaxPendingConnections;
 159        }
 160
 161        public override bool Equals(object obj)
 162        {
 0163            if (obj == null)
 164            {
 0165                return base.Equals(obj);
 166            }
 167
 0168            WebSocketTransportSettings settings = obj as WebSocketTransportSettings;
 0169            return Equals(settings);
 170        }
 171
 172        public override int GetHashCode()
 173        {
 0174            int hashcode = TransportUsage.GetHashCode()
 0175                        ^ CreateNotificationOnConnection.GetHashCode()
 0176                        ^ KeepAliveInterval.GetHashCode()
 0177                        ^ DisablePayloadMasking.GetHashCode()
 0178                        ^ MaxPendingConnections.GetHashCode();
 0179            if (SubProtocol != null)
 180            {
 0181                hashcode ^= SubProtocol.ToLowerInvariant().GetHashCode();
 182            }
 183
 0184            return hashcode;
 185        }
 186
 187        internal WebSocketTransportSettings Clone()
 188        {
 8768189            return new WebSocketTransportSettings(this);
 190        }
 191
 192        internal TimeSpan GetEffectiveKeepAliveInterval()
 193        {
 22194            return _keepAliveInterval == TimeSpan.Zero ? WebSocket.DefaultKeepAliveInterval : _keepAliveInterval;
 195        }
 196    }
 197}