< Summary

Information
Class: IceRpc.Internal.IceProtocol
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/IceProtocol.cs
Tag: 495_19924007549
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 61
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage
100%
Covered methods: 4
Total methods: 4
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Instance()100%11100%
CheckPath(...)100%44100%
CheckServiceAddressParams(...)100%66100%
.ctor()100%11100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Collections.Immutable;
 4
 5namespace IceRpc.Internal;
 6
 7/// <summary>The Ice protocol class.</summary>
 8internal sealed class IceProtocol : Protocol
 9{
 10    /// <summary>Gets the Ice protocol singleton.</summary>
 583711    internal static IceProtocol Instance { get; } = new();
 12
 13    /// <summary>Checks if this absolute path is well-formed.</summary>
 14    /// <remarks>This check is more lenient than the check performed when encoding a service address with Slice1 because
 15    /// we want the default path (`/`) to be a valid path for all protocols. Sending a request to a null/empty identity
 16    /// is in itself ok and will most likely result in a dispatch exception with a
 17    /// <see cref="StatusCode.NotFound" /> status code.</remarks>
 18    internal override void CheckPath(string uriPath)
 21119    {
 21120        string workingPath = uriPath[1..]; // removes leading /.
 21121        int firstSlash = workingPath.IndexOf('/', StringComparison.Ordinal);
 22
 23        // We can have at most one slash in the working path.
 21124        if (firstSlash != -1 && firstSlash != workingPath.LastIndexOf('/'))
 225        {
 226            throw new FormatException($"Too many slashes in path '{uriPath}'.");
 27        }
 20928    }
 29
 30    /// <summary>Checks if the service address parameters are valid. The only valid parameter is adapter-id with a
 31    /// non-empty value.</summary>
 32    internal override void CheckServiceAddressParams(ImmutableDictionary<string, string> serviceAddressParams)
 7333    {
 27434        foreach ((string name, string value) in serviceAddressParams)
 2935        {
 2936            if (name == "adapter-id")
 2837            {
 2838                if (value.Length == 0)
 239                {
 240                    throw new FormatException("The value of the adapter-id parameter cannot be empty.");
 41                }
 2642            }
 43            else
 144            {
 145                throw new FormatException($"Invalid ice service address parameter name '{name}'.");
 46            }
 2647        }
 7048    }
 49
 50    private IceProtocol()
 851        : base(
 852            name: "ice",
 853            defaultPort: 4061,
 854            hasFields: false,
 855            hasFragment: true,
 856            hasPayloadContinuation: false,
 857            supportsPayloadWriterInterceptors: false,
 858            byteValue: 1)
 859    {
 860    }
 61}