< Summary

Information
Class: IceRpc.OutgoingResponse
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/OutgoingResponse.cs
Tag: 276_17717543480
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>
 14313    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>
 79218    public IDictionary<ResponseFieldKey, OutgoingFieldValue> Fields { get; set; } =
 559019        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>
 1230323    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)
 545931        : base(request.Protocol)
 545932    {
 545933        request.Response = this;
 545934        StatusCode = StatusCode.Ok;
 545935    }
 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)
 13149        : base(request.Protocol)
 13150    {
 13151        request.Response = this;
 13152        StatusCode = statusCode > StatusCode.Ok ? statusCode :
 13153            throw new ArgumentException(
 13154                $"The status code for an exception must be greater than {nameof(StatusCode.Ok)}.",
 13155                nameof(statusCode));
 56
 13157        string errorMessage = message ?? $"The dispatch failed with status code {statusCode}.";
 13158        if (exception is not null)
 3759        {
 3760            errorMessage += $" The failure was caused by an exception of type '{exception.GetType()}' with message: {exc
 3761        }
 13162        ErrorMessage = errorMessage;
 13163    }
 64}