< Summary

Information
Class: IceRpc.Internal.ServerAddressExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/ServerAddressExtensions.cs
Tag: 701_22528036593
Line coverage
89%
Covered lines: 44
Uncovered lines: 5
Coverable lines: 49
Total lines: 82
Line coverage: 89.7%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
Method coverage
100%
Covered methods: 1
Total methods: 1
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AppendServerAddress(...)93.75%16.271689.79%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/ServerAddressExtensions.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Globalization;
 4using System.Text;
 5
 6namespace IceRpc.Internal;
 7
 8/// <summary>Provides extension methods for <see cref="ServerAddress" />.</summary>
 9internal static class ServerAddressExtensions
 10{
 11    /// <summary>Appends the server address and all its parameters (if any) to this string builder.</summary>
 12    /// <param name="sb">The string builder.</param>
 13    /// <param name="serverAddress">The server address to append.</param>
 14    /// <param name="path">The path of the server address URI. Use this parameter to start building a service address
 15    /// URI.</param>
 16    /// <param name="includeScheme">When <see langword="true" />, first appends the server address protocol followed by
 17    /// ://.</param>
 18    /// <param name="paramSeparator">The character that separates parameters in the query component of the URI.</param>
 19    /// <returns>The string builder <paramref name="sb" />.</returns>
 20    internal static StringBuilder AppendServerAddress(
 21        this StringBuilder sb,
 22        ServerAddress serverAddress,
 23        string path = "",
 24        bool includeScheme = true,
 25        char paramSeparator = '&')
 17826    {
 17827        if (includeScheme)
 17428        {
 17429            sb.Append(serverAddress.Protocol);
 17430            sb.Append("://");
 17431        }
 32
 17833        if (serverAddress.Host.Contains(':', StringComparison.Ordinal))
 034        {
 035            sb.Append('[');
 036            sb.Append(serverAddress.Host);
 037            sb.Append(']');
 038        }
 39        else
 17840        {
 17841            sb.Append(serverAddress.Host);
 17842        }
 43
 17844        if (serverAddress.Port != serverAddress.Protocol.DefaultPort)
 1345        {
 1346            sb.Append(':');
 1347            sb.Append(serverAddress.Port.ToString(CultureInfo.InvariantCulture));
 1348        }
 49
 17850        if (path.Length > 0)
 251        {
 252            sb.Append(path);
 253        }
 54
 17855        bool firstParam = true;
 17856        if (serverAddress.Transport is string transport)
 15557        {
 15558            firstParam = false;
 15559            sb.Append("?transport=").Append(transport);
 15560        }
 61
 56862        foreach ((string name, string value) in serverAddress.Params)
 1763        {
 1764            if (firstParam)
 365            {
 366                sb.Append('?');
 367                firstParam = false;
 368            }
 69            else
 1470            {
 1471                sb.Append(paramSeparator);
 1472            }
 1773            sb.Append(name);
 1774            if (value.Length > 0)
 1675            {
 1676                sb.Append('=');
 1677                sb.Append(value);
 1678            }
 1779        }
 17880        return sb;
 17881    }
 82}