< Summary

Information
Class: IceRpc.IncomingResponse
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/IncomingResponse.cs
Tag: 1856_27024993493
Line coverage
80%
Covered lines: 33
Uncovered lines: 8
Coverable lines: 41
Total lines: 121
Line coverage: 80.4%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage
100%
Covered methods: 7
Fully covered methods: 6
Total methods: 7
Method coverage: 100%
Full method coverage: 85.7%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ErrorMessage()100%11100%
get_Fields()100%11100%
get_StatusCode()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)66.66%8661.9%
Dispose()100%22100%

File(s)

/home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/IncomingResponse.cs

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Buffers;
 4using System.Collections.Immutable;
 5using System.IO.Pipelines;
 6
 7namespace IceRpc;
 8
 9/// <summary>Represents a response frame received by the application.</summary>
 10public sealed class IncomingResponse : IncomingFrame
 11{
 12    /// <summary>Gets the error message of this response.</summary>
 13    /// <value>The error message of this response. It is guaranteed to be non-<see langword="null" /> when <see
 14    /// cref="StatusCode" /> is different from <see cref="StatusCode.Ok" />, and <see langword="null" /> when <see
 15    /// cref="StatusCode" /> is <see cref="StatusCode.Ok" />.</value>
 6416    public string? ErrorMessage { get; }
 17
 18    /// <summary>Gets the fields of this incoming response.</summary>
 19    /// <value>The fields of this incoming response. Defaults to <see cref="ImmutableDictionary{TKey, TValue}.Empty"
 20    /// />.</value>
 606321    public IDictionary<ResponseFieldKey, ReadOnlySequence<byte>> Fields { get; private set; }
 22
 23    /// <summary>Gets the <see cref="StatusCode" /> of this response.</summary>
 24    /// <value>The <see cref="IceRpc.StatusCode" /> of this response.</value>
 41525    public StatusCode StatusCode { get; }
 26
 27    private readonly PipeReader? _fieldsPipeReader;
 28
 29    /// <summary>Constructs an incoming response with empty fields.</summary>
 30    /// <param name="request">The corresponding outgoing request.</param>
 31    /// <param name="connectionContext">The connection context of the connection that received this response.</param>
 32    /// <param name="statusCode">The status code of this response.</param>
 33    /// <param name="errorMessage">The error message of this response.</param>
 34    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 35    /// the request, its payload and payload continuation are completed.</remarks>
 36    public IncomingResponse(
 37        OutgoingRequest request,
 38        IConnectionContext connectionContext,
 39        StatusCode statusCode = StatusCode.Ok,
 40        string? errorMessage = null)
 262241        : this(
 262242            request,
 262243            connectionContext,
 262244            statusCode,
 262245            errorMessage,
 262246            ImmutableDictionary<ResponseFieldKey, ReadOnlySequence<byte>>.Empty,
 262247            fieldsPipeReader: null)
 262248    {
 262249    }
 50
 51    /// <summary>Constructs an incoming response.</summary>
 52    /// <param name="request">The corresponding outgoing request.</param>
 53    /// <param name="connectionContext">The connection context of the connection that received this response.</param>
 54    /// <param name="statusCode">The status code of this response.</param>
 55    /// <param name="errorMessage">The error message of this response.</param>
 56    /// <param name="fields">The fields of this response.</param>
 57    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 58    /// the request, its payload and payload continuation are completed.</remarks>
 59    public IncomingResponse(
 60        OutgoingRequest request,
 61        IConnectionContext connectionContext,
 62        StatusCode statusCode,
 63        string? errorMessage,
 64        IDictionary<ResponseFieldKey, ReadOnlySequence<byte>> fields)
 365        : this(request, connectionContext, statusCode, errorMessage, fields, fieldsPipeReader: null)
 366    {
 367    }
 68
 69    /// <summary>Constructs an incoming response with a pipe reader holding the memory for the fields.</summary>
 70    /// <param name="request">The corresponding outgoing request.</param>
 71    /// <param name="connectionContext">The connection context of the connection that received this response.</param>
 72    /// <param name="statusCode">The status code of this response.</param>
 73    /// <param name="errorMessage">The error message of this response.</param>
 74    /// <param name="fields">The fields of this response.</param>
 75    /// <param name="fieldsPipeReader">The pipe reader that holds the memory of the fields. Use <see langword="null"/>
 76    /// when the fields memory is not held by a pipe reader.</param>
 77    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 78    /// the request, its payload and payload continuation are completed.</remarks>
 79    internal IncomingResponse(
 80        OutgoingRequest request,
 81        IConnectionContext connectionContext,
 82        StatusCode statusCode,
 83        string? errorMessage,
 84        IDictionary<ResponseFieldKey, ReadOnlySequence<byte>> fields,
 85        PipeReader? fieldsPipeReader)
 301486        : base(request.Protocol, connectionContext)
 301487    {
 301488        if (statusCode == StatusCode.Ok)
 290789        {
 290790            if (errorMessage is not null)
 091            {
 092                throw new ArgumentException(
 093                    $"The {nameof(errorMessage)} argument must be null when {nameof(statusCode)} is {nameof(StatusCode.O
 094                    nameof(errorMessage));
 95            }
 290796        }
 10797        else if (errorMessage is null)
 098        {
 099            throw new ArgumentException(
 0100                $"The {nameof(errorMessage)} argument must be non-null when {nameof(statusCode)} is greater than {nameof
 0101                nameof(errorMessage));
 102        }
 103
 3014104        StatusCode = statusCode;
 3014105        ErrorMessage = errorMessage;
 3014106        Fields = fields;
 3014107        _fieldsPipeReader = fieldsPipeReader;
 3014108        request.Response = this;
 3014109    }
 110
 111    /// <summary>Completes the payload and releases the fields memory.</summary>
 112    /// <remarks>Dispose is internal because application code must dispose the outgoing request that owns this incoming
 113    /// response or create a different incoming response that disposes the previous response held by this outgoing
 114    /// request.</remarks>
 115    internal void Dispose()
 3011116    {
 3011117        Payload.Complete();
 3011118        _fieldsPipeReader?.Complete();
 3011119        Fields = ImmutableDictionary<ResponseFieldKey, ReadOnlySequence<byte>>.Empty;
 3011120    }
 121}