Class RestResponse
public sealed class RestResponse : ProtoHttpResponse, IDisposable, IProtoBinaryContent
- Inheritance
-
RestResponse
- Implements
- Inherited Members
- Extension Methods
Properties
ContentBytes
public ReadOnlyMemory<byte> ContentBytes { get; }
Property Value
ContentHeaders
public HttpContentHeaders ContentHeaders { get; }
Property Value
Headers
public HttpResponseHeaders Headers { get; }
Property Value
IsSuccessStatusCode
public bool IsSuccessStatusCode { get; }
Property Value
Should
The positive assertions on this response, such as Should.HaveHttpStatus(...) and
Should.MatchShape(...).
public RestShouldAssertions Should { get; }
Property Value
ShouldNot
Assertions that must not hold, such as ShouldNot.HaveHttpStatus(...). Shape assertions
stay on Should because a negated shape match is not meaningful.
public RestAssertions ShouldNot { get; }
Property Value
Methods
ReadAsAnonymous<T>(T, JsonSerializerOptions?)
Deserializes the body into an anonymous type described by example, e.g.
ReadAsAnonymous(new { id = 0, status = "" }).
public T? ReadAsAnonymous<T>(T anonymousTypeDefinition, JsonSerializerOptions? options = null)
Parameters
anonymousTypeDefinitionTOnly its type is used, so the compiler can infer the anonymous type; its values are ignored.
optionsJsonSerializerOptionsSerializer options; property names are case-insensitive by default.
Returns
- T
Type Parameters
T
ReadAsBytes()
public byte[] ReadAsBytes()
Returns
- byte[]
ReadAsDynamic()
public dynamic? ReadAsDynamic()
Returns
- dynamic
ReadAsJson<T>(string, JsonSerializerOptions?)
Reads a single value from the body at jsonPath and deserializes it as
T, for example ReadAsJson<int>("$.id"). The supported subset
is $, dot members and [n] indices (see JsonPathResolver); a leading
member without $ is accepted. An empty body returns default; a path that does not
resolve throws RestAssertionException naming the request identifier and
the path. Values of the wrong type throw JsonException, and the failure is traced
like any deserialization error, with the path.
public T? ReadAsJson<T>(string jsonPath, JsonSerializerOptions? options = null)
Parameters
jsonPathstringoptionsJsonSerializerOptions
Returns
- T
Type Parameters
T
ReadAsJson<T>(JsonSerializerOptions?)
Deserializes the whole body as T, or returns default for an empty
body. A failure records an http.response.deserialize event and rethrows.
public T? ReadAsJson<T>(JsonSerializerOptions? options = null)
Parameters
optionsJsonSerializerOptions
Returns
- T
Type Parameters
T
ReadRequired<T>(string, JsonSerializerOptions?)
Reads the value at jsonPath as T and fails when the
body is empty or the path holds JSON null, for every T including
value types, because the null check runs before the deserializer. A path that does not resolve
fails with the same subject and path as
ReadAsJson<T>(string, JsonSerializerOptions?).
public T ReadRequired<T>(string jsonPath, JsonSerializerOptions? options = null)
Parameters
jsonPathstringoptionsJsonSerializerOptions
Returns
- T
Type Parameters
T
ReadRequired<T>(JsonSerializerOptions?)
Reads the whole body as T and fails when there is nothing to return: an
empty body or JSON null throws RestAssertionException naming the request
identifier instead of returning default. Use it where the body is required;
ReadAsJson<T>(JsonSerializerOptions?) stays nullable.
public T ReadRequired<T>(JsonSerializerOptions? options = null)
Parameters
optionsJsonSerializerOptions
Returns
- T
Type Parameters
T
ShouldMatchShape(object, JsonSerializerOptions?)
Matches the response body against an expected shape through the same matcher REST, GraphQL, gRPC and messaging share.
[Obsolete("Use response.Should.MatchShape(shape) instead.")]
public RestResponse ShouldMatchShape(object expectedShape, JsonSerializerOptions? options = null)
Parameters
expectedShapeobjectoptionsJsonSerializerOptions
Returns
Remarks
Obsolete: use response.Should.MatchShape(shape).