< Summary

Information
Class: IceRpc.OutgoingResponse
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/OutgoingResponse.cs
Tag: 275_13775359185
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 64
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage
100%
Covered methods: 5
Total methods: 5
Method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ErrorMessage()100%11100%
get_Fields()100%11100%
.ctor(...)100%11100%
get_StatusCode()100%11100%
.ctor(...)83.33%66100%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using System.Collections.Immutable;
 4
 5namespace IceRpc;
 6
 7/// <summary>Represents a response frame sent by the application.</summary>
 8public sealed class OutgoingResponse : OutgoingFrame
 9{
 10    /// <summary>Gets the error message of this response.</summary>
 11    /// <value>The error message of this response if <see cref="StatusCode" /> is different from <see
 12    /// cref="StatusCode.Ok" />; otherwise, <see langword="null" />.</value>
 14113    public string? ErrorMessage { get; }
 14
 15    /// <summary>Gets or sets the fields of this response.</summary>
 16    /// <value>The fields of this incoming response. Defaults to <see cref="ImmutableDictionary{TKey, TValue}.Empty"
 17    /// />.</value>
 78818    public IDictionary<ResponseFieldKey, OutgoingFieldValue> Fields { get; set; } =
 558419        ImmutableDictionary<ResponseFieldKey, OutgoingFieldValue>.Empty;
 20
 21    /// <summary>Gets the status code of this response.</summary>
 22    /// <value>The <see cref="IceRpc.StatusCode" /> of this response.</value>
 1229523    public StatusCode StatusCode { get; }
 24
 25    /// <summary>Constructs an outgoing response with the <see cref="StatusCode.Ok" /> status code and a <see
 26    /// langword="null" /> error message.</summary>
 27    /// <param name="request">The incoming request.</param>
 28    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 29    /// the request, its payload and payload continuation are completed.</remarks>
 30    public OutgoingResponse(IncomingRequest request)
 545531        : base(request.Protocol)
 545532    {
 545533        request.Response = this;
 545534        StatusCode = StatusCode.Ok;
 545535    }
 36
 37    /// <summary>Constructs an outgoing response.</summary>
 38    /// <param name="request">The incoming request.</param>
 39    /// <param name="statusCode">The status code. It must be greater than <see cref="StatusCode.Ok" />.</param>
 40    /// <param name="message">The error message or null to use the default error message.</param>
 41    /// <param name="exception">The exception that is the cause of this failure.</param>
 42    /// <remarks>The constructor also associates this response with the request. If another response is already set on
 43    /// the request, its payload and payload continuation are completed.</remarks>
 44    public OutgoingResponse(
 45        IncomingRequest request,
 46        StatusCode statusCode,
 47        string? message = null,
 48        Exception? exception = null)
 12949        : base(request.Protocol)
 12950    {
 12951        request.Response = this;
 12952        StatusCode = statusCode > StatusCode.Ok ? statusCode :
 12953            throw new ArgumentException(
 12954                $"The status code for an exception must be greater than {nameof(StatusCode.Ok)}.",
 12955                nameof(statusCode));
 56
 12957        string errorMessage = message ?? $"The dispatch failed with status code {statusCode}.";
 12958        if (exception is not null)
 3759        {
 3760            errorMessage += $" The failure was caused by an exception of type '{exception.GetType()}' with message: {exc
 3761        }
 12962        ErrorMessage = errorMessage;
 12963    }
 64}