Class ProtoGrpcAssertions

Namespace
ProtoTest.Grpc
Assembly
ProtoTest.Grpc.dll

Shape and status assertions for gRPC replies, reusing the Json shape matcher the REST and GraphQL integrations use. Protobuf maps to Json with camelCase field names, so an expected anonymous shape reads the same way as elsewhere.

public static class ProtoGrpcAssertions
Inheritance
ProtoGrpcAssertions
Inherited Members

Methods

ShouldHaveStatus(RpcException, StatusCode)

Asserts the status of a failed call, untraced.

public static RpcException ShouldHaveStatus(this RpcException exception, StatusCode expected)

Parameters

exception RpcException
expected StatusCode

Returns

RpcException

ShouldHaveStatus(RpcException, StatusCode, ProtoExecutionContext?)

Asserts the status of a failed call and records the check on context as an assert.grpc.status operation with a Checks section. A mismatch fails the operation and rethrows a GrpcAssertionException; without a context the assertion is still made, untraced.

public static RpcException ShouldHaveStatus(this RpcException exception, StatusCode expected, ProtoExecutionContext? context = null)

Parameters

exception RpcException
expected StatusCode
context ProtoExecutionContext

Returns

RpcException

ShouldMatchShape<TResponse>(TResponse, ProtoExecutionContext, object, JsonSerializerOptions?)

Matches one protobuf reply against an expected shape and records the assertion on context as an assert.json.shape operation with a grpc.contract.shape observation. A mismatch fails the operation and rethrows the shape exception, so the evidence is in the trace even when the test fails.

public static void ShouldMatchShape<TResponse>(this TResponse response, ProtoExecutionContext context, object expectedShape, JsonSerializerOptions? options = null) where TResponse : IMessage

Parameters

response TResponse
context ProtoExecutionContext
expectedShape object
options JsonSerializerOptions

Type Parameters

TResponse

ShouldMatchShape<TResponse>(TResponse, object, JsonSerializerOptions?)

Matches one protobuf reply against an expected shape.

public static void ShouldMatchShape<TResponse>(this TResponse response, object expectedShape, JsonSerializerOptions? options = null) where TResponse : IMessage

Parameters

response TResponse
expectedShape object
options JsonSerializerOptions

Type Parameters

TResponse

ShouldNotHaveStatus(RpcException, StatusCode)

Asserts that a failed call does not carry unexpected, untraced.

public static RpcException ShouldNotHaveStatus(this RpcException exception, StatusCode unexpected)

Parameters

exception RpcException
unexpected StatusCode

Returns

RpcException

Remarks

Deliberate deviation: C# has no extension properties, so gRPC cannot expose the Should/ShouldNot facade REST and GraphQL use. ShouldNotHaveStatus delegates to the same implementation as ShouldHaveStatus with the polarity flipped, so the operation kind, trace name, Checks section, and failure message stay in one place.

ShouldNotHaveStatus(RpcException, StatusCode, ProtoExecutionContext?)

Asserts that a failed call does not carry unexpected and records the check as an assert.grpc.status operation with a Checks section. A mismatch fails the operation and rethrows a GrpcAssertionException; without a context the assertion is still made, untraced.

public static RpcException ShouldNotHaveStatus(this RpcException exception, StatusCode unexpected, ProtoExecutionContext? context = null)

Parameters

exception RpcException
unexpected StatusCode
context ProtoExecutionContext

Returns

RpcException

Remarks

Deliberate deviation: see ShouldNotHaveStatus for why gRPC has no Should facade.