Class ProtoStatusAssertion
The status assertion HTTP and gRPC responses share. It records one operation and Checks section for either protocol, names the expected status through the caller's description, and lets the caller supply the failure its own exception type. One implementation is what keeps a status assertion reading the same in every trace.
public static class ProtoStatusAssertion
- Inheritance
-
ProtoStatusAssertion
- Inherited Members
Methods
Assert(ProtoExecutionContext?, string, int, int, bool, Func<Exception>, string, string, string, string, IReadOnlyDictionary<string, string?>?, string?, string?)
Asserts two integer status codes (a gRPC status code, for example) with the caller's operation kind, attribute names and expected description, so a protocol with its own status vocabulary reuses the algorithm instead of copying it.
public static void Assert(ProtoExecutionContext? context, string source, int expected, int actual, bool negated, Func<Exception> failureFactory, string operationKind, string expectedDescription, string expectedAttribute, string actualAttribute, IReadOnlyDictionary<string, string?>? extraAttributes = null, string? parentOperationId = null, string? requestIdentifier = null)
Parameters
contextProtoExecutionContextsourcestringexpectedintactualintnegatedboolfailureFactoryFunc<Exception>operationKindstringexpectedDescriptionstringexpectedAttributestringactualAttributestringextraAttributesIReadOnlyDictionary<string, string>parentOperationIdstringrequestIdentifierstring
Assert(ProtoExecutionContext?, string, HttpStatusCode, HttpStatusCode, bool, Func<Exception>, string?, string?)
Asserts actual against expected, honoring
negated, and throws the exception failureFactory builds
when the assertion does not hold.
public static void Assert(ProtoExecutionContext? context, string source, HttpStatusCode expected, HttpStatusCode actual, bool negated, Func<Exception> failureFactory, string? parentOperationId = null, string? requestIdentifier = null)
Parameters
contextProtoExecutionContextThe execution context to trace on; a null context asserts without tracing.
sourcestringThe trace source, for example
ProtoTest.Rest.expectedHttpStatusCodeThe expected status.
actualHttpStatusCodeThe observed status.
negatedboolWhether the assertion asks for anything but
expected.failureFactoryFunc<Exception>Builds the exception thrown when the assertion does not hold.
parentOperationIdstringThe trace operation this assertion belongs under, if any.
requestIdentifierstringThe request or operation identifier recorded on the assertion.
DescribeFailure(HttpStatusCode, HttpStatusCode, bool, string?)
Builds the failure message both status assertions share, appending the sanitized response body when there is one, so a failed status reads the same whichever protocol produced it.
public static string DescribeFailure(HttpStatusCode expected, HttpStatusCode actual, bool negated, string? responseBody)
Parameters
expectedHttpStatusCodeactualHttpStatusCodenegatedboolresponseBodystring