Class ProtoHttpResponse
The shared half of an HTTP-based protocol response: the raw message and body, the execution context it was made in, the attachment naming state, the status assertion and disposal. A protocol derives from it and adds its own document model - REST adds binary and dynamic content, GraphQL the data/errors envelope - so a new HTTP-based integration starts from the same mechanics and keeps the same diagnostics contract.
public abstract class ProtoHttpResponse : IDisposable
- Inheritance
-
ProtoHttpResponse
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ProtoHttpResponse(HttpResponseMessage, string, TimeSpan, ProtoHttpResponseContext?)
protected ProtoHttpResponse(HttpResponseMessage rawResponse, string content, TimeSpan elapsed, ProtoHttpResponseContext? context = null)
Parameters
rawResponseHttpResponseMessagecontentstringelapsedTimeSpancontextProtoHttpResponseContext
Properties
AttachmentOptions
The redaction and capture rules the protocol resolved, when attachment capture is on.
protected ProtoHttpAttachmentOptions? AttachmentOptions { get; }
Property Value
AttachmentPrefix
The per-call attachment prefix, such as rest-01.
protected string? AttachmentPrefix { get; }
Property Value
Content
The body as text, exactly as the protocol read it.
public string Content { get; }
Property Value
Context
The test context the call was made in; null for an untraced assertion.
protected ProtoExecutionContext? Context { get; }
Property Value
ElapsedTime
public TimeSpan ElapsedTime { get; }
Property Value
Identifier
The operation identifier the protocol records on assertions and observations.
protected string? Identifier { get; }
Property Value
RawResponse
The response message this instance owns and disposes.
public HttpResponseMessage RawResponse { get; }
Property Value
RequestMethod
The HTTP method the call was made with, when the protocol knows it.
protected string? RequestMethod { get; }
Property Value
RequestTraceId
The trace operation that made the call, used as the parent of assertions.
protected string? RequestTraceId { get; }
Property Value
RouteTemplate
The route template the call was made against, when the protocol knows it.
protected string? RouteTemplate { get; }
Property Value
StatusCode
The response status.
public HttpStatusCode StatusCode { get; }
Property Value
TargetName
The target name the protocol reported the call under, when it has one.
protected string? TargetName { get; }
Property Value
Methods
AssertShape(string, string, string?, object, JsonSerializerOptions?, IReadOnlyDictionary<string, string?>, Func<IReadOnlyList<string>, ProtoObservation?>)
Asserts a JSON body's shape through the shared matcher, capturing the expected shape when the protocol opted in and recording the protocol's observation from the matched properties.
protected void AssertShape(string source, string title, string? actualJson, object expectedShape, JsonSerializerOptions? options, IReadOnlyDictionary<string, string?> extraAttributes, Func<IReadOnlyList<string>, ProtoObservation?> observation)
Parameters
sourcestringtitlestringactualJsonstringexpectedShapeobjectoptionsJsonSerializerOptionsextraAttributesIReadOnlyDictionary<string, string>observationFunc<IReadOnlyList<string>, ProtoObservation>
AssertShape(string, string, string?, object, JsonSerializerOptions?, IReadOnlyDictionary<string, string?>, Func<IReadOnlyList<string>, ProtoObservation?>, bool)
Asserts a JSON body's shape through the shared matcher; see AssertShape(string, string, string?, object, JsonSerializerOptions?, IReadOnlyDictionary<string, string?>, Func<IReadOnlyList<string>, ProtoObservation?>). In exact mode a field present in the body that the shape does not mention is a mismatch.
protected void AssertShape(string source, string title, string? actualJson, object expectedShape, JsonSerializerOptions? options, IReadOnlyDictionary<string, string?> extraAttributes, Func<IReadOnlyList<string>, ProtoObservation?> observation, bool exact)
Parameters
sourcestringtitlestringactualJsonstringexpectedShapeobjectoptionsJsonSerializerOptionsextraAttributesIReadOnlyDictionary<string, string>observationFunc<IReadOnlyList<string>, ProtoObservation>exactbool
AssertStatus(string, HttpStatusCode, bool, Func<Exception>)
Asserts the response status with the state this response carries and throws the exception
failureFactory builds when the assertion does not hold.
protected void AssertStatus(string source, HttpStatusCode expected, bool negated, Func<Exception> failureFactory)
Parameters
sourcestringexpectedHttpStatusCodenegatedboolfailureFactoryFunc<Exception>
Dispose()
Releases the underlying HTTP response. Callers own a returned response and should dispose it when access to RawResponse is no longer required; a protocol with its own document disposes that first and then calls this.
public virtual void Dispose()
NextExpectedShapeAttachmentName()
The name for the next expected-shape attachment, or null when the protocol did not opt in or the response was made without a context (an untraced assertion). The name carries a per-response sequence so repeated shape assertions stay distinct.
protected string? NextExpectedShapeAttachmentName()
Returns
ResolveStatusDiagnosticOptions(string)
The redaction options a status failure body uses: the protocol's configured response limit bounds it even when the protocol never opted into attachment capture, and attachment options, when present, keep their own redaction rules and may tighten the limit further. One helper for REST and GraphQL, so the clamp cannot drift between them.
protected ProtoHttpAttachmentOptions ResolveStatusDiagnosticOptions(string protocolName)
Parameters
protocolNamestring