Class StubAzureHttpPipelineTransport
- Namespace
- XBullet.EasyTesting.Azure
- Assembly
- XBullet.EasyTesting.Azure.dll
A scripted Azure SDK transport that records requests without using the network.
public sealed class StubAzureHttpPipelineTransport : HttpPipelineTransport, ITestScenarioResource
- Inheritance
-
StubAzureHttpPipelineTransport
- Implements
- Inherited Members
Remarks
Properties
CallCount
Gets the number of recorded requests.
public int CallCount { get; }
Property Value
- int
The total number of synchronous and asynchronous requests recorded since construction or reset.
RemainingResponseCount
Gets the number of arranged responses not yet consumed.
public int RemainingResponseCount { get; }
Property Value
- int
The non-negative number of queued response arrangements.
Requests
Gets a stable copy of recorded requests.
public IReadOnlyList<RecordedAzureRequest> Requests { get; }
Property Value
- IReadOnlyList<RecordedAzureRequest>
A newly allocated snapshot in call order. The caller may retain the list. Individual records contain unredacted URI queries, header values, and bodies that may be sensitive.
Methods
CaptureDiagnosticsAsync(CancellationToken)
Captures the current state before a failed scenario is cleaned up.
public ValueTask<object?> CaptureDiagnosticsAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels diagnostic collection for this resource. The default token does not request cancellation. A thrown exception, including cancellation, is recorded as a diagnostic capture failure so cleanup can continue.
Returns
- ValueTask<object>
A serializable diagnostic value, or null when the resource has no state to report. Ownership remains with the resource unless its implementation states otherwise.
CreateRequest()
Creates a new transport specific instance of Request. This should not be called directly, CreateRequest() or CreateMessage() should be used instead.
public override Request CreateRequest()
Returns
Process(HttpMessage)
Sends the request contained by the message and sets the Response property to received response synchronously.
public override void Process(HttpMessage message)
Parameters
messageHttpMessageThe HttpMessage containing request and response.
ProcessAsync(HttpMessage)
Sends the request contained by the message and sets the Response property to received response asynchronously.
public override ValueTask ProcessAsync(HttpMessage message)
Parameters
messageHttpMessageThe HttpMessage containing request and response.
Returns
Reset()
Clears arranged responses and recorded requests.
public StubAzureHttpPipelineTransport Reset()
Returns
- StubAzureHttpPipelineTransport
This transport, for chaining. Configured object identity is preserved.
ResetAsync(CancellationToken)
Clears mutable state before and after a scenario.
public ValueTask ResetAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels this reset attempt. The default token does not request cancellation. The factory continues resetting the remaining registered resources and reports all reset failures together.
Returns
- ValueTask
A task that completes when the resource has finished resetting its state.
Respond(Func<RecordedAzureRequest, Response>)
Enqueues a request-aware response factory for one request.
public StubAzureHttpPipelineTransport Respond(Func<RecordedAzureRequest, Response> responseFactory)
Parameters
responseFactoryFunc<RecordedAzureRequest, Response>A non-null callback retained until the next queued response is consumed, then invoked once with that request's stable record. It must return a non-null response whose ownership transfers to the Azure pipeline.
Returns
- StubAzureHttpPipelineTransport
This transport, for chaining. The factory is appended to the thread-safe queue.
Respond(int, BinaryData?, string?)
Enqueues a response status and optional body for one request.
public StubAzureHttpPipelineTransport Respond(int status = 200, BinaryData? content = null, string? contentType = null)
Parameters
statusintThe HTTP status code from 100 through 599. The default is 200. Validation occurs when the response is consumed.
contentBinaryDataThe optional response body retained until the arrangement is consumed. When null, the response has no body.
contentTypestringThe optional content-type header. A null, empty, or whitespace value is omitted, and the value is ignored when
contentis null.
Returns
- StubAzureHttpPipelineTransport
This transport, for chaining. One response is appended to the thread-safe queue.
RespondJson<T>(T, int, JsonSerializerOptions?)
Enqueues a JSON response for one request.
public StubAzureHttpPipelineTransport RespondJson<T>(T value, int status = 200, JsonSerializerOptions? serializerOptions = null)
Parameters
valueTThe value retained and serialized when the response is consumed; nullable values are accepted when
Tpermits them.statusintThe HTTP status code from 100 through 599. The default is 200. Validation occurs when consumed.
serializerOptionsJsonSerializerOptionsOptional JSON options retained until serialization, or null to use Azure BinaryData defaults.
Returns
- StubAzureHttpPipelineTransport
This transport, for chaining. One JSON response is appended to the queue.
Type Parameters
TThe type of value to serialize.
Verify(Func<RecordedAzureRequest, bool>, int, string?)
Verifies the number of requests accepted by a custom predicate.
public StubAzureHttpPipelineTransport Verify(Func<RecordedAzureRequest, bool> predicate, int expectedCount, string? description = null)
Parameters
predicateFunc<RecordedAzureRequest, bool>A non-null callback invoked once for each request in a stable snapshot. It returns true for matching requests and must not mutate transport state.
expectedCountintThe non-negative number of accepted requests expected.
descriptionstringOptional expectation text used in a failure message, or null, empty, or whitespace to use a generic description. Do not include secrets in this text.
Returns
- StubAzureHttpPipelineTransport
This transport when the expectation succeeds; otherwise, an exception is thrown.
VerifyCalled(RequestMethod, string, int)
Verifies a method and absolute URI, relative path, or relative path-and-query call count.
public StubAzureHttpPipelineTransport VerifyCalled(RequestMethod method, string requestUri, int expectedCount = 1)
Parameters
methodRequestMethodThe exact Azure request method to match.
requestUristringA non-empty absolute URI, root-relative path, or root-relative path and query. Absolute URIs match in full; relative values match the path, including the query only when one is supplied. Matching is ordinal and case-sensitive.
expectedCountintThe non-negative number of matching requests expected. The default is one.
Returns
- StubAzureHttpPipelineTransport
This transport when the expectation succeeds; otherwise, an exception is thrown.