Class StubClient
Creates a client for a test: over a handler of the test, in the fixed region us-east-1, with static fake credentials, one attempt per call and no attempt timeout. It reads nothing from the
environment, so a test behaves the same on a machine that has AWS_REGION, AWS_ENDPOINT_URL or a shared AWS file and on one that has none.
public static class StubClient
- Inheritance
-
StubClient
- Inherited Members
Examples
using var stub = new StubHandler();
using var client = StubClient.Create(stub);
stub.Enqueue(StubResponse.Item(order));
Remarks
The second argument adjusts the options the way a variation of DynamoDbClientOptions is written, with a with expression:
StubClient.Create(stub, options => options with { MaxAttempts = 4, TimeProvider = clock }). The client validates the result as it validates any options, and a null from the delegate
throws ArgumentNullException. Leave Credentials set: without it the client makes the default chain, which ends at the metadata endpoints on the network.
There is no attempt timeout because AttemptTimeout runs on TimeProvider: a fake clock that a test moves past it would time out the request the test is answering. So a test of a timeout sets one. A test that asks a responder of a StubHandler to wait for the cancellation of a call needs it, or it waits for ever.
The timeout of a wait for a table, WaitUntilActiveAsync and WaitUntilActive(), runs on that clock as well, next to the delays between its polls. So a loop that advances a fake clock and calls
Yield() until the wait ends burns the whole timeout, and the wait throws TableNotActiveException with answers still in the queue. Give such a wait a timeout that the loop does not reach,
or advance the clock once for each poll the handler has seen.
The client disposes neither the handler nor anything else it was given. A using on the client and one on the handler are both needed.
Methods
Create(HttpMessageHandler, Func<DynamoDbClientOptions, DynamoDbClientOptions>?)
Creates a DynamoDbClient over a handler.
public static DynamoDbClient Create(HttpMessageHandler handler, Func<DynamoDbClientOptions, DynamoDbClientOptions>? configure = null)
Parameters
handlerHttpMessageHandlerAnswers the requests, normally a StubHandler.
configureFunc<DynamoDbClientOptions, DynamoDbClientOptions>Adjusts the options with a
withexpression, or null to keep them.
Returns
- DynamoDbClient
The client.
Exceptions
- ArgumentNullException
- ArgumentOutOfRangeException
configuresets an AttemptTimeout or a MaxAttempts the client rejects.- ArgumentException
configuresets a ServiceUrl the client rejects.- InvalidOperationException
configureclears the region. The environment does not fill it in.
CreateStreams(HttpMessageHandler, Func<DynamoDbClientOptions, DynamoDbClientOptions>?)
Creates a DynamoDbStreamsClient over a handler, for the answers of DynamoDB Streams.
public static DynamoDbStreamsClient CreateStreams(HttpMessageHandler handler, Func<DynamoDbClientOptions, DynamoDbClientOptions>? configure = null)
Parameters
handlerHttpMessageHandlerAnswers the requests, normally a StubHandler.
configureFunc<DynamoDbClientOptions, DynamoDbClientOptions>Adjusts the options with a
withexpression, or null to keep them.
Returns
- DynamoDbStreamsClient
The client.
Exceptions
- ArgumentNullException
- ArgumentOutOfRangeException
configuresets an AttemptTimeout or a MaxAttempts the client rejects.- ArgumentException
configuresets a ServiceUrl the client rejects.- InvalidOperationException
configureclears the region. The environment does not fill it in.