< Summary

Information
Class: IceRpc.Internal.ServerAddressExtensions
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/ServerAddressExtensions.cs
Tag: 275_13775359185
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 = '&')
 33026    {
 33027        if (includeScheme)
 32228        {
 32229            sb.Append(serverAddress.Protocol);
 32230            sb.Append("://");
 32231        }
 32
 33033        if (serverAddress.Host.Contains(':', StringComparison.Ordinal))
 034        {
 035            sb.Append('[');
 036            sb.Append(serverAddress.Host);
 037            sb.Append(']');
 038        }
 39        else
 33040        {
 33041            sb.Append(serverAddress.Host);
 33042        }
 43
 33044        if (serverAddress.Port != serverAddress.Protocol.DefaultPort)
 2445        {
 2446            sb.Append(':');
 2447            sb.Append(serverAddress.Port.ToString(CultureInfo.InvariantCulture));
 2448        }
 49
 33050        if (path.Length > 0)
 451        {
 452            sb.Append(path);
 453        }
 54
 33055        bool firstParam = true;
 33056        if (serverAddress.Transport is string transport)
 29857        {
 29858            firstParam = false;
 29859            sb.Append("?transport=").Append(transport);
 29860        }
 61
 103262        foreach ((string name, string value) in serverAddress.Params)
 2163        {
 2164            if (firstParam)
 565            {
 566                sb.Append('?');
 567                firstParam = false;
 568            }
 69            else
 1670            {
 1671                sb.Append(paramSeparator);
 1672            }
 2173            sb.Append(name);
 2174            if (value.Length > 0)
 1975            {
 1976                sb.Append('=');
 1977                sb.Append(value);
 1978            }
 2179        }
 33080        return sb;
 33081    }
 82}