< Summary

Information
Class: IceRpc.Internal.IceProtocol
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/Internal/IceProtocol.cs
Tag: 275_13775359185
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>
 1097811    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)
 32419    {
 32420        string workingPath = uriPath[1..]; // removes leading /.
 32421        int firstSlash = workingPath.IndexOf('/', StringComparison.Ordinal);
 22
 23        // We can have at most one slash in the working path.
 32424        if (firstSlash != -1 && firstSlash != workingPath.LastIndexOf('/'))
 425        {
 426            throw new FormatException($"Too many slashes in path '{uriPath}'.");
 27        }
 32028    }
 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)
 11333    {
 42134        foreach ((string name, string value) in serviceAddressParams)
 4435        {
 4436            if (name == "adapter-id")
 4237            {
 4238                if (value.Length == 0)
 439                {
 440                    throw new FormatException("The value of the adapter-id parameter cannot be empty.");
 41                }
 3842            }
 43            else
 244            {
 245                throw new FormatException($"Invalid ice service address parameter name '{name}'.");
 46            }
 3847        }
 10748    }
 49
 50    private IceProtocol()
 951        : base(
 952            name: "ice",
 953            defaultPort: 4061,
 954            hasFields: false,
 955            hasFragment: true,
 956            hasPayloadContinuation: false,
 957            supportsPayloadWriterInterceptors: false,
 958            byteValue: 1)
 959    {
 960    }
 61}