< Summary

Information
Class: IceRpc.Transports.Tcp.TcpClientTransport
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Transports/Tcp/TcpClientTransport.cs
Tag: 1321_24790053727
Line coverage
91%
Covered lines: 41
Uncovered lines: 4
Coverable lines: 45
Total lines: 82
Line coverage: 91.1%
Branch coverage
76%
Covered branches: 20
Total branches: 26
Branch coverage: 76.9%
Method coverage
100%
Covered methods: 5
Fully covered methods: 3
Total methods: 5
Method coverage: 100%
Full method coverage: 60%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_DefaultName()100%11100%
IsSslRequired(...)50%7666.66%
.ctor()100%11100%
.ctor(...)100%11100%
CreateConnection(...)85%202094.11%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Transports/Tcp/TcpClientTransport.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Transports.Internal;
 4using IceRpc.Transports.Tcp.Internal;
 5using System.Net.Security;
 6
 7namespace IceRpc.Transports.Tcp;
 8
 9/// <summary>Implements <see cref="IDuplexClientTransport" /> for the tcp transport.</summary>
 10public class TcpClientTransport : IDuplexClientTransport
 11{
 12    /// <inheritdoc/>
 713    public string DefaultName => "tcp";
 14
 15    /// <inheritdoc/>
 1616    public bool IsSslRequired(string? transportName) => transportName switch
 1617    {
 1618        null or "tcp" => false,
 019        "ssl" => true,
 020        _ => throw new NotSupportedException($"The TCP client transport does not support transport '{transportName}'.")
 1621    };
 22
 23    private readonly TcpClientTransportOptions _options;
 24
 25    /// <summary>Constructs a <see cref="TcpClientTransport" />.</summary>
 26    public TcpClientTransport()
 2927        : this(new TcpClientTransportOptions())
 2928    {
 2929    }
 30
 31    /// <summary>Constructs a <see cref="TcpClientTransport" />.</summary>
 32    /// <param name="options">The transport options.</param>
 24433    public TcpClientTransport(TcpClientTransportOptions options) => _options = options;
 34
 35    /// <inheritdoc/>
 36    public IDuplexConnection CreateConnection(
 37        TransportAddress transportAddress,
 38        DuplexConnectionOptions options,
 39        SslClientAuthenticationOptions? clientAuthenticationOptions)
 14140    {
 41        // "ssl" is only accepted for the ice protocol, identified by the ALPN.
 14142        if (transportAddress.TransportName == "ssl")
 243        {
 244            if (clientAuthenticationOptions is null)
 145            {
 146                throw new ArgumentNullException(
 147                    nameof(clientAuthenticationOptions),
 148                    "The SSL client transport requires the SSL client authentication options to be set.");
 49            }
 150            else if (clientAuthenticationOptions.ApplicationProtocols is not List<SslApplicationProtocol> alpnProtocols 
 151                alpnProtocols.Count != 1 ||
 152                alpnProtocols[0] != new SslApplicationProtocol("ice"))
 053            {
 054                throw new NotSupportedException("The 'ssl' transport name is only supported with the ice protocol.");
 55            }
 156        }
 13957        else if (transportAddress.TransportName is string name && name != "tcp")
 158        {
 159            throw new NotSupportedException($"The TCP client transport does not support transport '{name}'.");
 60        }
 61
 13962        if (transportAddress.Params.Count > 0)
 463        {
 464            throw new ArgumentException(
 465                "The transport address contains parameters that are not valid for the TCP client transport.",
 466                nameof(transportAddress));
 67        }
 68
 13569        if (clientAuthenticationOptions is not null)
 3370        {
 3371            clientAuthenticationOptions = clientAuthenticationOptions.ShallowClone();
 3372            clientAuthenticationOptions.TargetHost ??= transportAddress.Host;
 3373        }
 74
 13575        return new TcpClientConnection(
 13576            transportAddress,
 13577            clientAuthenticationOptions,
 13578            options.Pool,
 13579            options.MinSegmentSize,
 13580            _options);
 13581    }
 82}