Table of Contents

Class ServerStreamAssertion<TResponse>

Namespace
GrpcAssertions.TUnit
Assembly
GrpcAssertions.TUnit.dll

Fluent TUnit assertion over the responses of an AsyncServerStreamingCall<TResponse>. Constructed by the Streams() entry point on a value assertion source; the chain methods (StreamsAtLeast, StreamsExactly, StreamContains) accumulate expectations and AndStreamItems runs follow-on assertions against the materialized responses.

public sealed class ServerStreamAssertion<TResponse> : Assertion<AsyncServerStreamingCall<TResponse>>, IAssertion

Type Parameters

TResponse

The streamed response message type.

Inheritance
Assertion<AsyncServerStreamingCall<TResponse>>
ServerStreamAssertion<TResponse>
Implements
IAssertion
Inherited Members
Assertion<AsyncServerStreamingCall<TResponse>>.AssertAsync()
Assertion<AsyncServerStreamingCall<TResponse>>.GetAwaiter()
Assertion<AsyncServerStreamingCall<TResponse>>.And
Assertion<AsyncServerStreamingCall<TResponse>>.Or

Remarks

The response stream is read exactly once, when the assertion is awaited: every accumulated expectation, and the optional AndStreamItems callback, runs against the single materialized list. A stream that faults mid-read (an RpcException from the reader) fails the assertion with the partial count and the rendered gRPC outcome.

Constructors

ServerStreamAssertion(AssertionContext<AsyncServerStreamingCall<TResponse>>, CancellationToken)

Initializes the assertion. Called by the Streams() entry point.

public ServerStreamAssertion(AssertionContext<AsyncServerStreamingCall<TResponse>> context, CancellationToken cancellationToken)

Parameters

context AssertionContext<AsyncServerStreamingCall<TResponse>>

The assertion context supplied by TUnit (the streaming call value).

cancellationToken CancellationToken

The token threaded into the response-stream read.

Methods

AndStreamItems(Func<IReadOnlyList<TResponse>, Task>)

Runs assertions against the materialized responses after the accumulated count and content expectations pass. The responses are already read, so the callback can assert on individual items without re-reading the stream.

public ServerStreamAssertion<TResponse> AndStreamItems(Func<IReadOnlyList<TResponse>, Task> assertions)

Parameters

assertions Func<IReadOnlyList<TResponse>, Task>

The follow-on assertions, applied to the response list. Must not be null.

Returns

ServerStreamAssertion<TResponse>

This assertion for chaining.

Exceptions

ArgumentNullException

assertions is null.

CheckAsync(EvaluationMetadata<AsyncServerStreamingCall<TResponse>>)

Implements the specific check logic for this assertion. Called after the context has been evaluated. Override this method if your assertion uses the default AssertAsync() flow. If you override AssertAsync() with custom logic (like AndAssertion/OrAssertion), you don't need to implement this.

protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<AsyncServerStreamingCall<TResponse>> metadata)

Parameters

metadata EvaluationMetadata<AsyncServerStreamingCall<TResponse>>

Metadata about the evaluation including value, exception, and timing information

Returns

Task<AssertionResult>

The result of the assertion check

GetExpectation()

Gets a human-readable description of what this assertion expects. Used in error messages.

protected override string GetExpectation()

Returns

string

StreamContains(Func<TResponse, bool>, string?)

Asserts at least one streamed response satisfies predicate.

public ServerStreamAssertion<TResponse> StreamContains(Func<TResponse, bool> predicate, string? predicateExpression = null)

Parameters

predicate Func<TResponse, bool>

The response predicate. Must not be null.

predicateExpression string

The source text of predicate, captured by the compiler for the failure message.

Returns

ServerStreamAssertion<TResponse>

This assertion for chaining.

Exceptions

ArgumentNullException

predicate is null.

StreamsAtLeast(int)

Asserts the stream produces at least count responses.

public ServerStreamAssertion<TResponse> StreamsAtLeast(int count)

Parameters

count int

The minimum response count. Must be non-negative.

Returns

ServerStreamAssertion<TResponse>

This assertion for chaining.

Exceptions

ArgumentOutOfRangeException

count is negative.

StreamsExactly(int)

Asserts the stream produces exactly count responses.

public ServerStreamAssertion<TResponse> StreamsExactly(int count)

Parameters

count int

The exact response count. Must be non-negative.

Returns

ServerStreamAssertion<TResponse>

This assertion for chaining.

Exceptions

ArgumentOutOfRangeException

count is negative.