< Summary

Information
Class: IceRpc.IncomingRequest
Assembly: IceRpc
File(s): /home/runner/work/icerpc-csharp/icerpc-csharp/src/IceRpc/IncomingRequest.cs
Tag: 278_19370051549
Line coverage
90%
Covered lines: 29
Uncovered lines: 3
Coverable lines: 32
Total lines: 94
Line coverage: 90.6%
Branch coverage
75%
Covered branches: 15
Total branches: 20
Branch coverage: 75%
Method coverage
91%
Covered methods: 11
Total methods: 12
Method coverage: 91.6%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Features()100%11100%
get_Fields()100%11100%
.ctor(...)100%11100%
get_Fragment()100%11100%
set_Fragment(...)50%44100%
get_IsOneway()100%11100%
get_Operation()100%11100%
get_Path()100%11100%
get_Response()100%11100%
set_Response(...)83.33%66100%
Dispose()100%88100%
ToString()0%620%

File(s)

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

#LineLine coverage
 1// Copyright (c) ZeroC, Inc.
 2
 3using IceRpc.Features;
 4using System.Buffers;
 5using System.Collections.Immutable;
 6
 7namespace IceRpc;
 8
 9/// <summary>Represents a request frame received by the application.</summary>
 10public sealed class IncomingRequest : IncomingFrame, IDisposable
 11{
 12    /// <summary>Gets or sets the features of this request.</summary>
 13    /// <value>The <see cref="IFeatureCollection" /> of this request. Defaults to <see cref="FeatureCollection.Empty"
 14    /// />.</value>
 652515    public IFeatureCollection Features { get; set; } = FeatureCollection.Empty;
 16
 17    /// <summary>Gets or sets the fields of this request.</summary>
 18    /// <value>The fields of this request. Defaults to <see cref="ImmutableDictionary{TKey, TValue}.Empty" />.</value>
 841619    public IDictionary<RequestFieldKey, ReadOnlySequence<byte>> Fields { get; set; } =
 566420        ImmutableDictionary<RequestFieldKey, ReadOnlySequence<byte>>.Empty;
 21
 22    /// <summary>Gets or initializes the fragment of the target service.</summary>
 23    /// <value>The fragment of the target service. It is always the empty string with the icerpc protocol. Defaults to
 24    /// the empty string.</value>
 25    public string Fragment
 26    {
 8227        get => _fragment;
 270928        init => _fragment = Protocol == Protocol.Ice || value.Length == 0 ? value :
 270929            throw new InvalidOperationException("Cannot create an icerpc request with a non-empty fragment.");
 30    }
 31
 32    /// <summary>Gets a value indicating whether this request is one-way or two-way.</summary>
 33    /// <value><see langword="true" /> for one-way requests; otherwise, <see langword="false" />. The default is
 34    /// <see langword="false" />.</value>
 1106635    public bool IsOneway { get; init; }
 36
 37    /// <summary>Gets or initializes the name of the operation to call on the target service.</summary>
 38    /// <value>The name of the operation. Defaults to the empty string.</value>
 1148139    public string Operation { get; init; } = "";
 40
 41    /// <summary>Gets or initializes the path of the target service.</summary>
 42    /// <value>The path of the target service. Defaults to <c>/</c>.</value>
 1151143    public string Path { get; init; } = "/";
 44
 45    /// <summary>Gets or sets the latest response for this request.</summary>
 46    /// <value>The request's latest response or <see langword="null"/> if the response is not set yet.</value>
 47    /// <remarks>Setting a response completes the previous response when there is one.</remarks>
 48    internal OutgoingResponse? Response
 49    {
 541950        get => _response;
 51        set
 558952        {
 558953            ObjectDisposedException.ThrowIf(_isDisposed, this);
 54
 558955            _response?.Payload.Complete();
 558956            _response?.PayloadContinuation?.Complete();
 558957            _response = value;
 558958        }
 59    }
 60
 566461    private readonly string _fragment = "";
 62
 63    // IncomingRequest is not thread-safe and does not accept a response after it is disposed.
 64    private bool _isDisposed;
 65
 66    private OutgoingResponse? _response;
 67
 68    /// <summary>Constructs an incoming request.</summary>
 69    /// <param name="protocol">The protocol of this request.</param>
 70    /// <param name="connectionContext">The connection context of the connection that received this request.</param>
 71    public IncomingRequest(Protocol protocol, IConnectionContext connectionContext)
 566472        : base(protocol, connectionContext)
 566473    {
 566474    }
 75
 76    /// <summary>Disposes this incoming request. This completes the payload of this request and the payload(s) of the
 77    /// response associated with this request (if set).</summary>
 78    public void Dispose()
 565979    {
 565980        if (!_isDisposed)
 565981        {
 565982            _isDisposed = true;
 565983            Payload.Complete();
 565984            _response?.Payload.Complete();
 565985            _response?.PayloadContinuation?.Complete();
 565986        }
 565987    }
 88
 89    /// <summary>Returns a string that represents this incoming request.</summary>
 90    /// <returns>A string that represents this incoming requests.</returns>
 091    public override string ToString() => Fragment.Length == 0 ?
 092        $"'{Operation}' on '{Path}'" :
 093        $"'{Operation}' on '{Path}#{Fragment}'";
 94}