Class ProtoStatusAssertion

Namespace
ProtoTest.Http
Assembly
ProtoTest.Http.dll

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

context ProtoExecutionContext
source string
expected int
actual int
negated bool
failureFactory Func<Exception>
operationKind string
expectedDescription string
expectedAttribute string
actualAttribute string
extraAttributes IReadOnlyDictionary<string, string>
parentOperationId string
requestIdentifier string

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

context ProtoExecutionContext

The execution context to trace on; a null context asserts without tracing.

source string

The trace source, for example ProtoTest.Rest.

expected HttpStatusCode

The expected status.

actual HttpStatusCode

The observed status.

negated bool

Whether the assertion asks for anything but expected.

failureFactory Func<Exception>

Builds the exception thrown when the assertion does not hold.

parentOperationId string

The trace operation this assertion belongs under, if any.

requestIdentifier string

The 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

expected HttpStatusCode
actual HttpStatusCode
negated bool
responseBody string

Returns

string