< Summary

Information
Class: IceRpc.Internal.ServerAddressExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/ServerAddressExtensions.cs
Tag: 1856_27024993493
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
Fully covered methods: 0
Total methods: 1
Method coverage: 100%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AppendServerAddress(...)93.75%161689.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 = '&')
 7626    {
 7627        if (includeScheme)
 7228        {
 7229            sb.Append(serverAddress.Protocol);
 7230            sb.Append("://");
 7231        }
 32
 7633        if (serverAddress.Host.Contains(':', StringComparison.Ordinal))
 034        {
 035            sb.Append('[');
 036            sb.Append(serverAddress.Host);
 037            sb.Append(']');
 038        }
 39        else
 7640        {
 7641            sb.Append(serverAddress.Host);
 7642        }
 43
 7644        if (serverAddress.Port != serverAddress.Protocol.DefaultPort)
 1345        {
 1346            sb.Append(':');
 1347            sb.Append(serverAddress.Port.ToString(CultureInfo.InvariantCulture));
 1348        }
 49
 7650        if (path.Length > 0)
 251        {
 252            sb.Append(path);
 253        }
 54
 7655        bool firstParam = true;
 7656        if (serverAddress.Transport is string transport)
 5257        {
 5258            firstParam = false;
 5259            sb.Append("?transport=").Append(transport);
 5260        }
 61
 26262        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        }
 7680        return sb;
 7681    }
 82}