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
exceptionRpcExceptionThe exception the call faults with. Must not be null.
Returns
- AsyncUnaryCall<TResponse>
A faulted AsyncUnaryCall<TResponse>.
Type Parameters
TResponseThe gRPC response message type.
Exceptions
- ArgumentNullException
exceptionis 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
statusCodeStatusCodeThe gRPC status code to fault with.
detailstringThe status detail message. A null value is treated as an empty string.
Returns
- AsyncUnaryCall<TResponse>
A faulted AsyncUnaryCall<TResponse>.
Type Parameters
TResponseThe 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
statusCodeStatusCodeThe gRPC status code to fault with.
detailstringThe status detail message. A null value is treated as an empty string.
trailersMetadataThe response trailers to attach. Must not be null.
Returns
- AsyncUnaryCall<TResponse>
A faulted AsyncUnaryCall<TResponse>.
Type Parameters
TResponseThe gRPC response message type.
Exceptions
- ArgumentNullException
trailersis 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
statusCodeStatusCodeThe gRPC status code the stream faults with after the responses.
responsesIEnumerable<TResponse>The responses yielded before the fault, in order. Must not be null; an empty sequence faults on the first read.
detailstringThe status detail message. A null value is treated as an empty string.
Returns
- AsyncServerStreamingCall<TResponse>
A faulted-after-
responsesAsyncServerStreamingCall<TResponse>.
Type Parameters
TResponseThe gRPC response message type.
Exceptions
- ArgumentNullException
responsesis 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
responsesIEnumerable<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
TResponseThe gRPC response message type.
Exceptions
- ArgumentNullException
responsesis 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
responseTResponseThe response the call completes with. Must not be null.
Returns
- AsyncUnaryCall<TResponse>
A completed, successful AsyncUnaryCall<TResponse>.
Type Parameters
TResponseThe gRPC response message type.
Exceptions
- ArgumentNullException
responseis 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
responseTResponseThe response the call completes with. Must not be null.
responseHeadersMetadataThe response headers, or null for empty headers.
trailersMetadataThe response trailers, or null for empty trailers.
Returns
- AsyncUnaryCall<TResponse>
A completed, successful AsyncUnaryCall<TResponse>.
Type Parameters
TResponseThe gRPC response message type.
Exceptions
- ArgumentNullException
responseis null.