< Summary

Information
Class: IceRpc.OutgoingRequest
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/OutgoingRequest.cs
Tag: 275_13775359185
Line coverage
92%
Covered lines: 25
Uncovered lines: 2
Coverable lines: 27
Total lines: 79
Line coverage: 92.5%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage
80%
Covered methods: 8
Total methods: 10
Method coverage: 80%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Features()100%11100%
get_Fields()100%11100%
.ctor(...)50%22100%
get_IsOneway()100%11100%
get_Operation()100%11100%
get_ServiceAddress()100%11100%
get_Response()100%210%
set_Response(...)100%22100%
Dispose()100%66100%
ToString()100%210%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Features;
 4using System.Collections.Immutable;
 5
 6namespace IceRpc;
 7
 8/// <summary>Represents a request frame sent by the application.</summary>
 9public sealed class OutgoingRequest : OutgoingFrame, IDisposable
 10{
 11    /// <summary>Gets or sets the features of this request.</summary>
 12    /// <value>The <see cref="IFeatureCollection" /> of this request. Defaults to <see
 13    /// cref="FeatureCollection.Empty" />.</value>
 665514    public IFeatureCollection Features { get; set; } = FeatureCollection.Empty;
 15
 16    /// <summary>Gets or sets the fields of this request.</summary>
 17    /// <value>The fields of this request. Defaults to <see cref="ImmutableDictionary{TKey, TValue}.Empty" />.</value>
 844718    public IDictionary<RequestFieldKey, OutgoingFieldValue> Fields { get; set; } =
 573719        ImmutableDictionary<RequestFieldKey, OutgoingFieldValue>.Empty;
 20
 21    /// <summary>Gets a value indicating whether this request is one-way or two-way.</summary>
 22    /// <value><see langword="true" /> for one-way requests; otherwise, <see langword="false" />. The default is
 23    /// <see langword="false" />.</value>
 1518324    public bool IsOneway { get; init; }
 25
 26    /// <summary>Gets or initializes the name of the operation to call on the target service.</summary>
 27    /// <value>The name of the operation. The default is the empty string.</value>
 1153828    public string Operation { get; init; } = "";
 29
 30    /// <summary>Gets the address of the target service.</summary>
 31    /// <value>The <see cref="ServiceAddress" /> of this request.</value>
 1145432    public ServiceAddress ServiceAddress { get; }
 33
 34    /// <summary>Gets or sets the latest response for this request.</summary>
 35    /// <value>The request's latest response or <see langword="null"/> if the response is not set yet.</value>
 36    /// <remarks>Setting a response completes the previous response when there is one.</remarks>
 37    internal IncomingResponse? Response
 38    {
 039        get => _response;
 40        set
 558341        {
 558342            ObjectDisposedException.ThrowIf(_isDisposed, this);
 43
 558344            _response?.Dispose();
 558345            _response = value;
 558346        }
 47    }
 48
 49    // OutgoingRequest is not thread-safe and should not receive a response after it is disposed.
 50    private bool _isDisposed;
 51
 52    private IncomingResponse? _response;
 53
 54    /// <summary>Constructs an outgoing request.</summary>
 55    /// <param name="serviceAddress">The address of the target service.</param>
 56    public OutgoingRequest(ServiceAddress serviceAddress)
 573757        : base(serviceAddress.Protocol ??
 573758            throw new ArgumentException(
 573759                "An outgoing request requires a service address with a protocol such as icerpc or ice.",
 573760                nameof(serviceAddress))) =>
 573761        ServiceAddress = serviceAddress;
 62
 63    /// <summary>Disposes this outgoing request. This completes the payload and payload continuation of this request,
 64    /// and the response associated with this request (if already received).</summary>
 65    public void Dispose()
 576266    {
 576267        if (!_isDisposed)
 573468        {
 573469            _isDisposed = true;
 573470            Payload.Complete();
 573471            PayloadContinuation?.Complete();
 573472            _response?.Dispose();
 573473        }
 576274    }
 75
 76    /// <summary>Returns a string that represents this outgoing request.</summary>
 77    /// <returns>A string that represents this outgoing request.</returns>
 078    public override string ToString() => $"'{Operation}' on '{ServiceAddress}'";
 79}