Table of Contents

Class GrpcCallBuilder

Namespace
GrpcAssertions
Assembly
GrpcAssertions.dll

Builds AsyncUnaryCall<TResponse> instances for gRPC client test doubles, eliminating the five-parameter constructor that every hand-rolled fake repeats. These are test-infrastructure helpers, not assertions, so they live in the framework-agnostic core GrpcAssertions package rather than the TUnit adapter.

public static class GrpcCallBuilder
Inheritance
GrpcCallBuilder
Inherited Members

Methods

Faulted<TResponse>(RpcException)

Builds a faulted AsyncUnaryCall<TResponse> whose response task throws exception, surfacing the exception's Status and Trailers through the call's status and trailers accessors.

public static AsyncUnaryCall<TResponse> Faulted<TResponse>(RpcException exception)

Parameters

exception RpcException

The exception the call faults with. Must not be null.

Returns

AsyncUnaryCall<TResponse>

A faulted AsyncUnaryCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Exceptions

ArgumentNullException

exception is null.

Faulted<TResponse>(StatusCode, string?)

Builds a faulted AsyncUnaryCall<TResponse> from a status code and detail, the most common faulted-call shape in tests: a convenience over Faulted<TResponse>(RpcException) that constructs the RpcException for the caller.

public static AsyncUnaryCall<TResponse> Faulted<TResponse>(StatusCode statusCode, string? detail = null)

Parameters

statusCode StatusCode

The gRPC status code to fault with.

detail string

The status detail message. A null value is treated as an empty string.

Returns

AsyncUnaryCall<TResponse>

A faulted AsyncUnaryCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Faulted<TResponse>(StatusCode, string?, Metadata)

Builds a faulted AsyncUnaryCall<TResponse> from a status code, detail, and response trailers. The trailers are attached to the constructed RpcException, so they surface through the call's trailers accessor and through Trailers on the thrown exception.

public static AsyncUnaryCall<TResponse> Faulted<TResponse>(StatusCode statusCode, string? detail, Metadata trailers)

Parameters

statusCode StatusCode

The gRPC status code to fault with.

detail string

The status detail message. A null value is treated as an empty string.

trailers Metadata

The response trailers to attach. Must not be null.

Returns

AsyncUnaryCall<TResponse>

A faulted AsyncUnaryCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Exceptions

ArgumentNullException

trailers is null.

ServerStreamingFaulted<TResponse>(StatusCode, IEnumerable<TResponse>, string?)

Builds an AsyncServerStreamingCall<TResponse> whose response stream yields responses in order and then throws an RpcException on the next read: the partial-stream-then-error shape that exercises a wrapper's mid-stream fault handling.

public static AsyncServerStreamingCall<TResponse> ServerStreamingFaulted<TResponse>(StatusCode statusCode, IEnumerable<TResponse> responses, string? detail = null)

Parameters

statusCode StatusCode

The gRPC status code the stream faults with after the responses.

responses IEnumerable<TResponse>

The responses yielded before the fault, in order. Must not be null; an empty sequence faults on the first read.

detail string

The status detail message. A null value is treated as an empty string.

Returns

AsyncServerStreamingCall<TResponse>

A faulted-after-responses AsyncServerStreamingCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Exceptions

ArgumentNullException

responses is null.

ServerStreaming<TResponse>(IEnumerable<TResponse>)

Builds a successful AsyncServerStreamingCall<TResponse> whose response stream yields responses in order and then ends cleanly with a terminal OK status: the server-streaming shape a generated gRPC client returns on success.

public static AsyncServerStreamingCall<TResponse> ServerStreaming<TResponse>(IEnumerable<TResponse> responses)

Parameters

responses IEnumerable<TResponse>

The responses the stream yields, in order. Must not be null; an empty sequence produces a stream that ends immediately.

Returns

AsyncServerStreamingCall<TResponse>

A successful AsyncServerStreamingCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Exceptions

ArgumentNullException

responses is null.

Success<TResponse>(TResponse)

Builds a successful AsyncUnaryCall<TResponse> that completes with response, empty response headers and trailers, and a terminal OK status: the unary-call shape a generated gRPC client returns on success.

public static AsyncUnaryCall<TResponse> Success<TResponse>(TResponse response)

Parameters

response TResponse

The response the call completes with. Must not be null.

Returns

AsyncUnaryCall<TResponse>

A completed, successful AsyncUnaryCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Exceptions

ArgumentNullException

response is null.

Success<TResponse>(TResponse, Metadata?, Metadata?)

Builds a successful AsyncUnaryCall<TResponse> that completes with response and the supplied response headers and trailers, and a terminal OK status. A null responseHeaders or trailers is treated as empty metadata. The trailers accessor returns the same Metadata instance on every call, matching a real client.

public static AsyncUnaryCall<TResponse> Success<TResponse>(TResponse response, Metadata? responseHeaders, Metadata? trailers)

Parameters

response TResponse

The response the call completes with. Must not be null.

responseHeaders Metadata

The response headers, or null for empty headers.

trailers Metadata

The response trailers, or null for empty trailers.

Returns

AsyncUnaryCall<TResponse>

A completed, successful AsyncUnaryCall<TResponse>.

Type Parameters

TResponse

The gRPC response message type.

Exceptions

ArgumentNullException

response is null.