< Summary

Information
Class: IceRpc.IncomingResponse
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/IncomingResponse.cs
Tag: 275_13775359185
Line coverage
80%
Covered lines: 33
Uncovered lines: 8
Coverable lines: 41
Total lines: 120
Line coverage: 80.4%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage
100%
Covered methods: 7
Total methods: 7
Method coverage: 100%

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%7.99661.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 if <see cref="StatusCode" /> is different from <see
 14    /// cref="StatusCode.Ok" />; otherwise, <see langword="null"/>.</value>
 5715    public string? ErrorMessage { get; }
 16
 17    /// <summary>Gets the fields of this incoming response.</summary>
 18    /// <value>The fields of this incoming response. Defaults to <see cref="ImmutableDictionary{TKey, TValue}.Empty"
 19    /// />.</value>
 1120220    public IDictionary<ResponseFieldKey, ReadOnlySequence<byte>> Fields { get; private set; }
 21
 22    /// <summary>Gets the <see cref="StatusCode" /> of this response.</summary>
 23    /// <value>The <see cref="IceRpc.StatusCode" /> of this response.</value>
 34824    public StatusCode StatusCode { get; }
 25
 26    private readonly PipeReader? _fieldsPipeReader;
 27
 28    /// <summary>Constructs an incoming response with empty fields.</summary>
 29    /// <param name="request">The corresponding outgoing request.</param>
 30    /// <param name="connectionContext">The connection context of the connection that received this response.</param>
 31    /// <param name="statusCode">The status code of this response.</param>
 32    /// <param name="errorMessage">The error message of this response.</param>
 33    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 34    /// the request, its payload and payload continuation are completed.</remarks>
 35    public IncomingResponse(
 36        OutgoingRequest request,
 37        IConnectionContext connectionContext,
 38        StatusCode statusCode = StatusCode.Ok,
 39        string? errorMessage = null)
 486940        : this(
 486941            request,
 486942            connectionContext,
 486943            statusCode,
 486944            errorMessage,
 486945            ImmutableDictionary<ResponseFieldKey, ReadOnlySequence<byte>>.Empty,
 486946            fieldsPipeReader: null)
 486947    {
 486948    }
 49
 50    /// <summary>Constructs an incoming response.</summary>
 51    /// <param name="request">The corresponding outgoing request.</param>
 52    /// <param name="connectionContext">The connection context of the connection that received this response.</param>
 53    /// <param name="statusCode">The status code of this response.</param>
 54    /// <param name="errorMessage">The error message of this response.</param>
 55    /// <param name="fields">The fields of this response.</param>
 56    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 57    /// the request, its payload and payload continuation are completed.</remarks>
 58    public IncomingResponse(
 59        OutgoingRequest request,
 60        IConnectionContext connectionContext,
 61        StatusCode statusCode,
 62        string? errorMessage,
 63        IDictionary<ResponseFieldKey, ReadOnlySequence<byte>> fields)
 364        : this(request, connectionContext, statusCode, errorMessage, fields, fieldsPipeReader: null)
 365    {
 366    }
 67
 68    /// <summary>Constructs an incoming response with a pipe reader holding the memory for the fields.</summary>
 69    /// <param name="request">The corresponding outgoing request.</param>
 70    /// <param name="connectionContext">The connection context of the connection that received this response.</param>
 71    /// <param name="statusCode">The status code of this response.</param>
 72    /// <param name="errorMessage">The error message of this response.</param>
 73    /// <param name="fields">The fields of this response.</param>
 74    /// <param name="fieldsPipeReader">The pipe reader that holds the memory of the fields. Use <see langword="null"/>
 75    /// when the fields memory is not held by a pipe reader.</param>
 76    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 77    /// the request, its payload and payload continuation are completed.</remarks>
 78    internal IncomingResponse(
 79        OutgoingRequest request,
 80        IConnectionContext connectionContext,
 81        StatusCode statusCode,
 82        string? errorMessage,
 83        IDictionary<ResponseFieldKey, ReadOnlySequence<byte>> fields,
 84        PipeReader? fieldsPipeReader)
 558385        : base(request.Protocol, connectionContext)
 558386    {
 558387        if (statusCode == StatusCode.Ok)
 545988        {
 545989            if (errorMessage is not null)
 090            {
 091                throw new ArgumentException(
 092                    $"The {nameof(errorMessage)} argument must be null when {nameof(statusCode)} is {nameof(StatusCode.O
 093                    nameof(errorMessage));
 94            }
 545995        }
 12496        else if (errorMessage is null)
 097        {
 098            throw new ArgumentException(
 099                $"The {nameof(errorMessage)} argument must be non-null when {nameof(statusCode)} is greater than {nameof
 0100                nameof(errorMessage));
 101        }
 102
 5583103        StatusCode = statusCode;
 5583104        ErrorMessage = errorMessage;
 5583105        Fields = fields;
 5583106        _fieldsPipeReader = fieldsPipeReader;
 5583107        request.Response = this;
 5583108    }
 109
 110    /// <summary>Completes the payload and releases the fields memory.</summary>
 111    /// <remarks>Dispose is internal because application code must dispose the outgoing request that owns this incoming
 112    /// response or create a different incoming response that disposes the previous response held by this outgoing
 113    /// request.</remarks>
 114    internal void Dispose()
 5580115    {
 5580116        Payload.Complete();
 5580117        _fieldsPipeReader?.Complete();
 5580118        Fields = ImmutableDictionary<ResponseFieldKey, ReadOnlySequence<byte>>.Empty;
 5580119    }
 120}