Class ProtoGrpcAssertions
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
For(RpcException)
The assertion facade for a failed call: ProtoGrpcAssertions.For(exception).Should.HaveStatus(...),
or .ShouldNot for the negated form. The extension methods remain only because C# has no
extension properties.
public static ProtoGrpcExceptionAssertions For(RpcException exception)
Parameters
exceptionRpcException
Returns
For<TResponse>(TResponse)
The assertion facade of one reply message: ProtoGrpcAssertions.For(reply).Should.MatchShape(shape).
C# has no extension properties, so a message reaches its Should through this factory.
public static ProtoGrpcMessageAssertions<TResponse> For<TResponse>(TResponse response) where TResponse : IMessage
Parameters
responseTResponse
Returns
- ProtoGrpcMessageAssertions<TResponse>
Type Parameters
TResponse
ShouldHaveStatus(RpcException, StatusCode)
Asserts the status of a failed call, traced on the ambient context.
[Obsolete("Use ProtoGrpcAssertions.For(exception).Should.HaveStatus(expected) instead.")]
public static RpcException ShouldHaveStatus(this RpcException exception, StatusCode expected)
Parameters
exceptionRpcExceptionexpectedStatusCode
Returns
Remarks
Obsolete: use ProtoGrpcAssertions.For(exception).Should.HaveStatus(expected).
ShouldMatchShape<TResponse>(TResponse, object, JsonSerializerOptions?)
Matches one protobuf reply against an expected shape and records the assertion on the ambient
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. Returns the message, so
shape assertions chain.
[Obsolete("Use ProtoGrpcAssertions.For(response).Should.MatchShape(shape) instead.")]
public static TResponse ShouldMatchShape<TResponse>(this TResponse response, object expectedShape, JsonSerializerOptions? options = null) where TResponse : IMessage
Parameters
responseTResponseexpectedShapeobjectoptionsJsonSerializerOptions
Returns
- TResponse
Type Parameters
TResponse
Remarks
Obsolete: use ProtoGrpcAssertions.For(response).Should.MatchShape(shape).
ShouldNotHaveStatus(RpcException, StatusCode)
Asserts that a failed call does not carry unexpected.
[Obsolete("Use ProtoGrpcAssertions.For(exception).ShouldNot.HaveStatus(unexpected) instead.")]
public static RpcException ShouldNotHaveStatus(this RpcException exception, StatusCode unexpected)
Parameters
exceptionRpcExceptionunexpectedStatusCode
Returns
Remarks
Obsolete: use ProtoGrpcAssertions.For(exception).ShouldNot.HaveStatus(unexpected).