Class TestAzureResponse

Namespace
XBullet.EasyTesting.Azure
Assembly
XBullet.EasyTesting.Azure.dll

A concrete, configurable Azure SDK response for tests.

public sealed class TestAzureResponse : Response, IDisposable
Inheritance
TestAzureResponse
Implements
Inherited Members

Constructors

TestAzureResponse(int, string?)

Creates a response with the supplied HTTP status.

public TestAzureResponse(int status = 200, string? reasonPhrase = null)

Parameters

status int

The HTTP status code from 100 through 599. The default is 200.

reasonPhrase string

The reason phrase, or null to derive the standard phrase for known status codes. Unknown codes receive an empty phrase. An explicitly empty phrase is preserved.

Properties

ClientRequestId

Gets the client request id that was sent to the server as x-ms-client-request-id headers.

public override string ClientRequestId { get; set; }

Property Value

string

ContentStream

Gets the contents of HTTP response. Returns null for responses without content.

public override Stream? ContentStream { get; set; }

Property Value

Stream

ReasonPhrase

Gets the HTTP reason phrase.

public override string ReasonPhrase { get; }

Property Value

string

Status

Gets the HTTP status code.

public override int Status { get; }

Property Value

int

Methods

ContainsHeader(string)

Returns true if the header is stored in the collection.

protected override bool ContainsHeader(string name)

Parameters

name string

The header name.

Returns

bool

true if the specified header is stored in the collection, otherwise false.

Dispose()

Frees resources held by this Response instance.

public override void Dispose()

EnumerateHeaders()

Returns an iterator for enumerating HttpHeader in the response.

protected override IEnumerable<HttpHeader> EnumerateHeaders()

Returns

IEnumerable<HttpHeader>

The IEnumerable<T> enumerating HttpHeader in the response.

FromValue<T>(T)

Wraps a model value and this raw response in an Azure Response<T>.

public Response<T> FromValue<T>(T value)

Parameters

value T

The model value to retain; nullable values are accepted when T permits them.

Returns

Response<T>

A model response containing value and this exact raw response. This response remains caller-owned and must not be disposed while the wrapper is in use.

Type Parameters

T

The type of model value carried by the response.

TryGetHeader(string, out string)

Returns header value if the header is stored in the collection. If header has multiple values they are going to be joined with a comma.

protected override bool TryGetHeader(string name, out string value)

Parameters

name string

The header name.

value string

The reference to populate with value.

Returns

bool

true if the specified header is stored in the collection, otherwise false.

TryGetHeaderValues(string, out IEnumerable<string>)

Returns header values if the header is stored in the collection.

protected override bool TryGetHeaderValues(string name, out IEnumerable<string> values)

Parameters

name string

The header name.

values IEnumerable<string>

The reference to populate with values.

Returns

bool

true if the specified header is stored in the collection, otherwise false.

WithContent(BinaryData, string?)

Sets the binary response body and optional content type.

public TestAzureResponse WithContent(BinaryData content, string? contentType = null)

Parameters

content BinaryData

The non-null binary content to copy into a new read-only stream. The caller retains ownership of the supplied value.

contentType string

The content-type header to add or replace, or null, empty, or whitespace to leave that header unchanged. The content-length header is always replaced with the byte count.

Returns

TestAzureResponse

This response, for chaining. Any previous content stream is disposed and replaced immediately.

WithHeader(string, string)

Adds or replaces a response header.

public TestAzureResponse WithHeader(string name, string value)

Parameters

name string

The non-empty, non-whitespace header name. Names are matched case-insensitively.

value string

The non-null header value. An empty value is accepted.

Returns

TestAzureResponse

This response, for chaining. Any existing values for the header are replaced.

WithHeader(string, params string[])

Adds or replaces a multi-value response header.

public TestAzureResponse WithHeader(string name, params string[] values)

Parameters

name string

The non-empty, non-whitespace header name. Names are matched case-insensitively.

values string[]

The non-null array of non-null header values. Empty strings and an empty array are accepted; the array is copied before this method returns.

Returns

TestAzureResponse

This response, for chaining. Any existing values for the header are replaced.

WithJsonContent<T>(T, JsonSerializerOptions?)

Serializes a JSON response body.

public TestAzureResponse WithJsonContent<T>(T value, JsonSerializerOptions? serializerOptions = null)

Parameters

value T

The value to serialize; nullable values are accepted when T permits them.

serializerOptions JsonSerializerOptions

The JSON options to use, or null to use Azure BinaryData defaults.

Returns

TestAzureResponse

This response, for chaining, with a copied JSON body, an application/json content type, and a matching content length. Any previous content stream is disposed.

Type Parameters

T

The type of value to serialize.