< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.NetTcpSecurity
Assembly: CoreWCF.NetTcp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/NetTcpSecurity.cs
Line coverage
87%
Covered lines: 21
Uncovered lines: 3
Coverable lines: 24
Total lines: 81
Line coverage: 87.5%
Branch coverage
64%
Covered branches: 9
Total branches: 14
Branch coverage: 64.2%
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(...)50%44100%
CreateTransportSecurity()100%44100%
CreateMessageSecurity(...)50%4460%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetTcp/src/CoreWCF/NetTcpSecurity.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.ComponentModel;
 6using CoreWCF.Channels;
 7using CoreWCF.Runtime;
 8using CoreWCF.Security;
 9
 10namespace CoreWCF
 11{
 12    public sealed partial class NetTcpSecurity
 13    {
 14        internal const SecurityMode DefaultMode = SecurityMode.Transport;
 15        private SecurityMode _mode;
 16
 17        public NetTcpSecurity()
 11718            : this(DefaultMode, new TcpTransportSecurity(), new MessageSecurityOverTcp())
 19        {
 11720        }
 21
 11722        private NetTcpSecurity(SecurityMode mode, TcpTransportSecurity transportSecurity, MessageSecurityOverTcp message
 23        {
 24            Fx.Assert(SecurityModeHelper.IsDefined(mode), string.Format("Invalid SecurityMode value: {0}.", mode.ToStrin
 25
 11726            _mode = mode;
 11727            Transport = transportSecurity ?? new TcpTransportSecurity();
 11728            Message = messageSecurity ?? new MessageSecurityOverTcp();
 11729        }
 30
 31        [DefaultValue(DefaultMode)]
 32        public SecurityMode Mode
 33        {
 224734            get { return _mode; }
 35            set
 36            {
 10937                if (!SecurityModeHelper.IsDefined(value))
 38                {
 039                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 40                }
 10941                _mode = value;
 10942            }
 43        }
 44
 149545        public TcpTransportSecurity Transport { get; set; }
 46
 16647        public MessageSecurityOverTcp Message { get; set; }
 48
 49        internal BindingElement CreateTransportSecurity()
 50        {
 115951            if (_mode == SecurityMode.TransportWithMessageCredential)
 52            {
 7453                return Transport.CreateTransportProtectionOnly();
 54            }
 108555            else if (_mode == SecurityMode.Transport)
 56            {
 17257                return Transport.CreateTransportProtectionAndAuthentication();
 58            }
 59            else
 60            {
 91361                return null;
 62            }
 63        }
 64
 65        internal SecurityBindingElement CreateMessageSecurity(bool isReliableSessionEnabled)
 66        {
 3767            if (_mode == SecurityMode.Message)
 68            {
 069                return Message.CreateSecurityBindingElement(false, isReliableSessionEnabled, null);
 70            }
 3771            else if (_mode == SecurityMode.TransportWithMessageCredential)
 72            {
 3773                return Message.CreateSecurityBindingElement(true, isReliableSessionEnabled, CreateTransportSecurity());
 74            }
 75            else
 76            {
 077                return null;
 78            }
 79        }
 80    }
 81}