Class StubResponse
A canned HTTP response for a StubHandler.
public sealed class StubResponse
- Inheritance
-
StubResponse
- Inherited Members
Remarks
The body is sent as application/x-amz-json-1.0, the content type of DynamoDB. A test says what DynamoDB answers and leaves the JSON to this class:
Item<T>(T?) for GetItem, Items<T>(IEnumerable<T>, int?) for a page of Query or Scan, Attributes<T>(T?) for
a write that returns values, ConditionalCheckFailed<T>(T?) and TransactionCanceled(params ReadOnlySpan<CancellationReason>) for failed conditions,
and Unprocessed(string, params ReadOnlySpan<WriteRequest>) with BatchItems<T>(string, IEnumerable<T>) for batches. They take an Item as well as a
generated entity, and they write through the code the entity is stored with, so a canned item cannot drift from the mapping. An Item can hold any
attributes, which is how a test gives the partial answer of UPDATED_NEW. Count(int, int?) answers a Select: COUNT.
Table administration has Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>) and Table<T>(string, TableStatus) for DescribeTable, TableCreated(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>), TableUpdated(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>), TableDeleted(string),
TablesListed(params ReadOnlySpan<string>) for ListTables, TimeToLive(TimeToLiveStatus, string?), TimeToLiveUpdated(bool, string), ResourceNotFound() and ResourceInUse(). DynamoDB Streams has StreamDescription(string, params ReadOnlySpan<Shard>),
ShardIterator(string) and Records(string?, params ReadOnlySpan<ChangeRecord>). What such an answer holds beyond its arguments is fixed: the region of StubClient, an account, a creation time of 2026-01-01, so a test can
compare it and no answer depends on the clock.
A response holds what DynamoDB sends by default. ConsumedCapacity and ItemCollectionMetrics come only when a request asks for them, so a test that reads them
writes the body with Json(string, HttpStatusCode, IReadOnlyDictionary<string, string>?), as it does for TransactGetItems and anything unusual. DynamoDbError(string, string, HttpStatusCode, string?) makes every other error.
An answer is for its operations. A response of a factory is the answer to the operations its body is written for, as each factory says, and a StubHandler that hands it to a request
of another operation throws. The client would read most such bodies without complaint: the answer of an UpdateTimeToLive taken by a GetItem reads as no item, and a test that expects none
passes for the wrong reason. The errors go by what they are for: ConditionalCheckFailed() answers a PutItem, an UpdateItem or a DeleteItem, and
TransactionCanceled(params ReadOnlySpan<TransactionFailure>) a TransactWriteItems or a TransactGetItems. ResourceNotFound() and ResourceInUse() have the
shape of an error that many operations return, and fit any, as do Json(string, HttpStatusCode, IReadOnlyDictionary<string, string>?), DynamoDbError(string, string, HttpStatusCode, string?) and new StubResponse(), whose body the test writes or which has none.
Constructors
StubResponse()
public StubResponse()
Properties
Body
Gets the response body, normally a JSON document. Defaults to an empty JSON object. Can be any text to simulate a broken response, for example the HTML of a proxy.
public string Body { get; init; }
Property Value
Headers
Gets additional response headers by name, for example x-amzn-RequestId. Headers that belong to the content, such as
Content-Type, replace the defaults.
public IReadOnlyDictionary<string, string>? Headers { get; init; }
Property Value
StatusCode
Gets the HTTP status code. Defaults to OK.
public HttpStatusCode StatusCode { get; init; }
Property Value
Methods
Attributes<T>(T?)
Creates the answer to a PutItem, UpdateItem or DeleteItem that asked for values: {"Attributes":{...}}, or {} if there are none, as for
ReturnOld() on a key that held no item. The answer to a write that asked for nothing is new StubResponse().
public static StubResponse Attributes<T>(T? attributes) where T : IDynamoDbDocument<T>
Parameters
attributesTThe attributes, or null for none.
Returns
- StubResponse
The response.
Type Parameters
TThe type of the attributes: a generated entity for a whole item, or Item, also for the few attributes of
Return(attr).
BatchItems<T>(string, IEnumerable<T>)
Creates the answer to a BatchGetItem that read everything, on one table. Items come in no particular order, and a key without an item is simply absent.
public static StubResponse BatchItems<T>(string tableName, IEnumerable<T> items) where T : IDynamoDbDocument<T>
Parameters
tableNamestringThe table of the items.
itemsIEnumerable<T>The items, which may be none.
Returns
- StubResponse
The response.
Type Parameters
TThe type of the items: a generated entity or Item.
Exceptions
- ArgumentNullException
tableNameoritemsis null.
Change(OperationType, Item, Item?, Item?, string?)
Creates a record from attributes, for Records(string?, params ReadOnlySpan<ChangeRecord>): images of an Item, or a record without images, as a stream with KeysOnly has them. Whatever the images, the record says
NewAndOldImages, the stream of StreamDescription(string, params ReadOnlySpan<Shard>). ChangeRecord and StreamRecord are records, so with changes the rest.
public static ChangeRecord Change(OperationType eventName, Item keys, Item? oldImage = null, Item? newImage = null, string? sequenceNumber = null)
Parameters
eventNameOperationTypeWhat happened to the item.
keysItemThe key attributes, as KeyOf<T>(T) makes them from an entity.
oldImageItemThe item before the change, or null for none.
newImageItemThe item after the change, or null for none.
sequenceNumberstringThe sequence number, or null for one from the position in the page.
Returns
- ChangeRecord
The record.
Exceptions
- ArgumentNullException
keysis null.
ConditionalCheckFailed()
Creates the error of a write whose condition did not hold, without the item: what DynamoDB sends unless the request set ReturnOldOnFailure().
public static StubResponse ConditionalCheckFailed()
Returns
- StubResponse
The response: HTTP 400 with
ConditionalCheckFailedException.
ConditionalCheckFailedReason<T>(T?)
Creates the reason of an action whose condition did not hold, with the item the condition saw, as an action with ReturnOldOnFailure() gets it.
public static CancellationReason ConditionalCheckFailedReason<T>(T? item) where T : IDynamoDbDocument<T>
Parameters
itemTThe item, or null if none existed under the key.
Returns
- CancellationReason
The reason.
Type Parameters
TThe type of the item: a generated entity or Item.
ConditionalCheckFailed<T>(T?)
Creates the error of a write whose condition did not hold, with the item the condition saw, as ReturnOldOnFailure() gets it.
public static StubResponse ConditionalCheckFailed<T>(T? item) where T : IDynamoDbDocument<T>
Parameters
itemTThe item, or null if none existed under the key.
Returns
- StubResponse
The response: HTTP 400 with
ConditionalCheckFailedException.
Type Parameters
TThe type of the item: a generated entity or Item.
Count(int, Item, int?)
Creates a page of a count that more pages follow: CountAsync goes on from lastEvaluatedKey and adds the pages up.
public static StubResponse Count(int count, Item lastEvaluatedKey, int? scannedCount = null)
Parameters
countintHow many items are in the page after the filter.
lastEvaluatedKeyItemThe key of the last item DynamoDB read, as KeyOf<T>(T) makes it from an entity.
scannedCountint?How many items DynamoDB read before the filter, or null for
count.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
lastEvaluatedKeyis null.- ArgumentOutOfRangeException
countis negative, orscannedCountis below it, which DynamoDB never sends.
Count(int, IKey, int?)
Creates a page of a count that more pages follow, with a generated key.
public static StubResponse Count(int count, IKey lastEvaluatedKey, int? scannedCount = null)
Parameters
countintHow many items are in the page after the filter.
lastEvaluatedKeyIKeyThe key of the last item DynamoDB read.
scannedCountint?How many items DynamoDB read before the filter, or null for
count.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
lastEvaluatedKeyis null.- ArgumentOutOfRangeException
countis negative, orscannedCountis below it, which DynamoDB never sends.
Count(int, int?)
Creates a page of a Query or Scan with Select: COUNT that ends the read: {"Count":3,"ScannedCount":3}, without Items, as CountAsync gets it. ScannedCount is the same unless a test says that a
filter dropped items.
public static StubResponse Count(int count, int? scannedCount = null)
Parameters
countintHow many items are in the page after the filter.
scannedCountint?How many items DynamoDB read before the filter, or null for
count.
Returns
- StubResponse
The response.
Exceptions
- ArgumentOutOfRangeException
countis negative, orscannedCountis below it, which DynamoDB never sends.
Delete(Item)
Creates a delete for Unprocessed(string, params ReadOnlySpan<WriteRequest>).
public static WriteRequest Delete(Item key)
Parameters
keyItemThe attributes of the key, as KeyOf<T>(T) makes them from an entity.
Returns
- WriteRequest
The write.
Exceptions
- ArgumentNullException
keyis null.
Delete(IKey)
Creates a delete by a generated key for Unprocessed(string, params ReadOnlySpan<WriteRequest>).
public static WriteRequest Delete(IKey key)
Parameters
keyIKeyThe key.
Returns
- WriteRequest
The write.
Exceptions
- ArgumentNullException
keyis null.
DynamoDbError(string, string, HttpStatusCode, string?)
Creates an error response in the shape DynamoDB uses: {"__type":"com.amazonaws.dynamodb.v20120810#Code","message":"..."}.
public static StubResponse DynamoDbError(string errorCode, string message, HttpStatusCode statusCode = HttpStatusCode.BadRequest, string? requestId = null)
Parameters
errorCodestringThe error code without namespace, for example
ResourceNotFoundExceptionorThrottlingException.messagestringThe error message.
statusCodeHttpStatusCodeThe HTTP status code. DynamoDB answers client errors with 400 and server errors with 500.
requestIdstringThe value of the
x-amzn-RequestIdheader, or null for none.
Returns
- StubResponse
The response.
GlobalIndex(string, IndexStatus)
Creates a global index for Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>), projecting all attributes, with one string key attribute named after it, ByCustomer_pk. A wait reads the name and
the status. It is a record, so a test says the rest with with: GlobalIndex("ByCustomer", IndexStatus.Creating) with { Backfilling = true }.
public static GlobalSecondaryIndexDescription GlobalIndex(string indexName, IndexStatus status = IndexStatus.Active)
Parameters
indexNamestringThe name of the index.
statusIndexStatusThe status of the index.
Returns
- GlobalSecondaryIndexDescription
The index.
Exceptions
- ArgumentNullException
indexNameis null.
Inserted<T>(T, string?)
Creates the record of a new item, for Records(string?, params ReadOnlySpan<ChangeRecord>).
public static ChangeRecord Inserted<T>(T newImage, string? sequenceNumber = null) where T : IDynamoDbEntity<T>
Parameters
newImageTThe item, written as it is stored, and the source of the key.
sequenceNumberstringThe sequence number, or null for one from the position in the page.
Returns
- ChangeRecord
The record.
Type Parameters
TThe entity. Change(OperationType, Item, Item?, Item?, string?) takes an Item, which does not say what its key is.
Exceptions
- ArgumentNullException
newImageis null.
Item<T>(T?)
Creates the answer to a GetItem: {"Item":{...}}, or {} if there is no item, which is how DynamoDB says that it found nothing.
public static StubResponse Item<T>(T? item) where T : IDynamoDbDocument<T>
Parameters
itemTThe item, or null for a miss. A struct cannot be null: the miss of a struct entity is
new StubResponse().
Returns
- StubResponse
The response.
Type Parameters
TThe type of the item: a generated entity or Item.
Items<T>(IEnumerable<T>, Item, int?)
Creates a page that more pages follow: the read goes on from lastEvaluatedKey, also when a filter left the page empty. A fan-out also takes this key as a hint for its merge,
so a made-up sort key reorders the items there: use the overload that takes an DynaSharp.Mapping.IKey.
public static StubResponse Items<T>(IEnumerable<T> items, Item lastEvaluatedKey, int? scannedCount = null) where T : IDynamoDbDocument<T>
Parameters
itemsIEnumerable<T>The items, which may be none.
lastEvaluatedKeyItemThe key of the last item DynamoDB read, as KeyOf<T>(T) makes it from an entity.
scannedCountint?How many items DynamoDB read before the filter, or null for as many as
itemsholds.
Returns
- StubResponse
The response.
Type Parameters
TThe type of the items: a generated entity or Item.
Exceptions
- ArgumentNullException
itemsorlastEvaluatedKeyis null.- ArgumentOutOfRangeException
scannedCountis below the number of items, which DynamoDB never sends.
Items<T>(IEnumerable<T>, IKey, int?)
Creates a page that more pages follow, with a generated key: Items(orders, Order.Keys.Of("alice", 7)).
public static StubResponse Items<T>(IEnumerable<T> items, IKey lastEvaluatedKey, int? scannedCount = null) where T : IDynamoDbDocument<T>
Parameters
itemsIEnumerable<T>The items, which may be none.
lastEvaluatedKeyIKeyThe key of the last item DynamoDB read.
scannedCountint?How many items DynamoDB read before the filter, or null for as many as
itemsholds.
Returns
- StubResponse
The response.
Type Parameters
TThe type of the items: a generated entity or Item.
Exceptions
- ArgumentNullException
itemsorlastEvaluatedKeyis null.- ArgumentOutOfRangeException
scannedCountis below the number of items, which DynamoDB never sends.
Items<T>(IEnumerable<T>, int?)
Creates a page of a Query or Scan that ends the read, with Count filled in. ScannedCount is the same unless a test says that a filter dropped items.
public static StubResponse Items<T>(IEnumerable<T> items, int? scannedCount = null) where T : IDynamoDbDocument<T>
Parameters
itemsIEnumerable<T>The items, which may be none.
scannedCountint?How many items DynamoDB read before the filter, or null for as many as
itemsholds.
Returns
- StubResponse
The response.
Type Parameters
TThe type of the items: a generated entity or Item.
Remarks
A generated entity is written with its keys, as a Put writes it. An Item is written as it stands, and a read of an entity restores what its keys hold from the item: a
required input of a key that the item lacks throws DynamoDbMappingException, which names the key. So an Item for such an entity holds the keys as well, for which
KeyOf<T>(T) gives the attributes.
Exceptions
- ArgumentNullException
itemsis null.- ArgumentOutOfRangeException
scannedCountis below the number of items, which DynamoDB never sends.
Json(string, HttpStatusCode, IReadOnlyDictionary<string, string>?)
Creates a response with a JSON body.
public static StubResponse Json(string json, HttpStatusCode statusCode = HttpStatusCode.OK, IReadOnlyDictionary<string, string>? headers = null)
Parameters
jsonstringThe body, for example
{"Item":{"pk":{"S":"a"}}}.statusCodeHttpStatusCodeThe HTTP status code. DynamoDB answers successful requests with 200.
headersIReadOnlyDictionary<string, string>Additional response headers, or null.
Returns
- StubResponse
The response.
KeyOf(IKey)
Gets the attributes of a generated key, so that a test can compare it with ReadKey().
public static Item KeyOf(IKey key)
Parameters
keyIKeyThe key.
Returns
- Item
A new item that holds the key attributes.
Exceptions
- ArgumentNullException
keyis null.
KeyOf<T>(T)
Gets the key attributes of an entity, as a request for it would carry them.
public static Item KeyOf<T>(T entity) where T : IDynamoDbEntity<T>
Parameters
entityTThe entity.
Returns
- Item
A new item that holds the key attributes.
Type Parameters
TThe type of the entity.
Exceptions
- ArgumentNullException
entityis null.
Keys(params ReadOnlySpan<Item>)
Puts keys together for Unprocessed(string, KeysAndAttributes).
public static KeysAndAttributes Keys(params ReadOnlySpan<Item> keys)
Parameters
keysReadOnlySpan<Item>The attributes of each key, as KeyOf<T>(T) makes them from an entity.
Returns
- KeysAndAttributes
The keys.
Keys(params ReadOnlySpan<IKey>)
Puts generated keys together for Unprocessed(string, KeysAndAttributes).
public static KeysAndAttributes Keys(params ReadOnlySpan<IKey> keys)
Parameters
keysReadOnlySpan<IKey>The generated keys.
Returns
- KeysAndAttributes
The keys, ready for a response.
Exceptions
- ArgumentNullException
A key is null.
Modified<T>(T, T, string?)
Creates the record of a changed item, with both images, for Records(string?, params ReadOnlySpan<ChangeRecord>).
public static ChangeRecord Modified<T>(T oldImage, T newImage, string? sequenceNumber = null) where T : IDynamoDbEntity<T>
Parameters
oldImageTThe item before the change.
newImageTThe item after the change, and the source of the key.
sequenceNumberstringThe sequence number, or null for one from the position in the page.
Returns
- ChangeRecord
The record.
Type Parameters
TThe entity. Change(OperationType, Item, Item?, Item?, string?) takes an Item, which does not say what its key is.
Exceptions
- ArgumentNullException
oldImageornewImageis null.
Put<T>(T)
Creates a put for Unprocessed(string, params ReadOnlySpan<WriteRequest>).
public static WriteRequest Put<T>(T item) where T : IDynamoDbDocument<T>
Parameters
itemTThe item.
Returns
- WriteRequest
The write.
Type Parameters
TThe type of the item: a generated entity or Item.
Exceptions
- ArgumentNullException
itemis null.
Reason(TransactionFailure)
Creates the reason of one action as DynamoDB words it. Throttled stands for two codes and sends ThrottlingError; a
CancellationReason of your own sends ProvisionedThroughputExceeded.
public static CancellationReason Reason(TransactionFailure failure)
Parameters
failureTransactionFailureThe failure.
Returns
- CancellationReason
The reason.
Exceptions
- ArgumentOutOfRangeException
failureis Unknown, which has no code, or not a member of the enum.
Records(string?, params ReadOnlySpan<ChangeRecord>)
Creates the answer to a GetRecords: Records("next", StubResponse.Inserted(order), StubResponse.Removed(other)). A record without EventId or
SequenceNumber gets one from its position in the page, so that the records of a page differ. The next page starts over, so a test of a checkpoint gives the numbers.
public static StubResponse Records(string? nextShardIterator, params ReadOnlySpan<ChangeRecord> records)
Parameters
nextShardIteratorstringThe iterator of the next page. On an open shard there is always one, also for a page without records. null says that a closed shard was read to its end.
recordsReadOnlySpan<ChangeRecord>The records, as Inserted<T>(T, string?), Modified<T>(T, T, string?), Removed<T>(T, string?) and Change(OperationType, Item, Item?, Item?, string?) make them. A record is sent with what it holds.
Returns
- StubResponse
The response.
Removed<T>(T, string?)
Creates the record of a deleted item, for Records(string?, params ReadOnlySpan<ChangeRecord>). A delete by time to live also has a UserIdentity, which a test adds:
Removed(order) with { UserIdentity = new RecordIdentity { PrincipalId = "dynamodb.amazonaws.com", Type = "Service" } }.
public static ChangeRecord Removed<T>(T oldImage, string? sequenceNumber = null) where T : IDynamoDbEntity<T>
Parameters
oldImageTThe item before the delete, and the source of the key.
sequenceNumberstringThe sequence number, or null for one from the position in the page.
Returns
- ChangeRecord
The record.
Type Parameters
TThe entity. Change(OperationType, Item, Item?, Item?, string?) takes an Item, which does not say what its key is.
Exceptions
- ArgumentNullException
oldImageis null.
ResourceInUse()
Creates the error of a table that cannot change now: it exists already on a CreateTable, or it is CREATING, UPDATING or DELETING.
public static StubResponse ResourceInUse()
Returns
- StubResponse
The response: HTTP 400 with
ResourceInUseException.
ResourceNotFound()
Creates the error of a table, an index or a stream that does not exist, or of a table that is not active yet for a call that needs it to be.
public static StubResponse ResourceNotFound()
Returns
- StubResponse
The response: HTTP 400 with
ResourceNotFoundException.
Shard(string, string?, string?)
Creates a shard for StreamDescription(string, params ReadOnlySpan<Shard>). A shard without an end is open: DynamoDB still writes to it.
public static Shard Shard(string shardId, string? parentShardId = null, string? endingSequenceNumber = null)
Parameters
shardIdstringThe id of the shard, which a
GetShardIteratornames.parentShardIdstringThe shard this one split from, or null for a shard without a parent.
endingSequenceNumberstringThe last sequence number of a closed shard, or null for an open one.
Returns
- Shard
The shard.
Exceptions
- ArgumentNullException
shardIdis null.
ShardIterator(string)
Creates the answer to a GetShardIterator: {"ShardIterator":"..."}.
public static StubResponse ShardIterator(string iterator)
Parameters
iteratorstringThe iterator, which a
GetRecordsof the test then sends.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
iteratoris null.
StreamDescription(StreamDescription)
Creates the answer to a DescribeStream from a whole description, for what a test cares about: a status that is not ENABLED, or LastEvaluatedShardId for a page that more shards
follow. It sends what the description holds and adds nothing.
public static StubResponse StreamDescription(StreamDescription description)
Parameters
descriptionStreamDescriptionThe description.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
descriptionis null.
StreamDescription(string, StreamStatus, params ReadOnlySpan<Shard>)
Creates the answer to a DescribeStream of the stream of a table with the key pk, with old and new images, in a status: StreamDescription("Shop", StreamStatus.Disabled, shard)
for a stream that was switched off, whose shards are all closed and which opens no more.
public static StubResponse StreamDescription(string tableName, StreamStatus status, params ReadOnlySpan<Shard> shards)
Parameters
tableNamestringThe table of the stream.
statusStreamStatusThe status of the stream. Unknown sends none.
shardsReadOnlySpan<Shard>The shards, as Shard(string, string?, string?) makes them.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
tableNameis null.
StreamDescription(string, params ReadOnlySpan<Shard>)
Creates the answer to a DescribeStream of the enabled stream of a table with the key pk, with old and new images: {"StreamDescription":{...}}. Read the ARN from the response, or give one with the
StreamDescription(StreamDescription) overload, which also says the rest.
public static StubResponse StreamDescription(string tableName, params ReadOnlySpan<Shard> shards)
Parameters
tableNamestringThe table of the stream.
shardsReadOnlySpan<Shard>The shards, as Shard(string, string?, string?) makes them.
Returns
- StubResponse
The response.
Remarks
An enabled stream can still open shards, so ReadStreamAsync keeps looking for the children of a closed shard while it lists none. A script whose last shard closes
without children answers with StreamDescription(string, StreamStatus, params ReadOnlySpan<Shard>) and Disabled, which ends the reading.
Exceptions
- ArgumentNullException
tableNameis null.
Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>)
Creates the answer to a DescribeTable: a table on demand and empty, with a string partition key pk, the indexes given and their key attributes,
{"Table":{...}}. The arguments say what a wait or a check reads, and the rest is what DynamoDB sends for such a table, so that the body stays one DynamoDB could have sent.
public static StubResponse Table(string name, TableStatus status = TableStatus.Active, params ReadOnlySpan<GlobalSecondaryIndexDescription> globalIndexes)
Parameters
namestringThe table name.
statusTableStatusThe status of the table.
globalIndexesReadOnlySpan<GlobalSecondaryIndexDescription>The global secondary indexes, as GlobalIndex(string, IndexStatus) makes them.
Returns
- StubResponse
The response.
Remarks
A table reads ACTIVE while an index it was given later is built, which is what a wait looks at: Table("Orders", TableStatus.Active, GlobalIndex("ByCustomer", IndexStatus.Creating)), queued in front of
Table("Orders", TableStatus.Active, GlobalIndex("ByCustomer")). Table<T>(string, TableStatus) takes the key and the indexes from an entity. Other values, such as LatestStreamArn, are a body for Json(string, HttpStatusCode, IReadOnlyDictionary<string, string>?).
Exceptions
- ArgumentNullException
nameis null.- ArgumentOutOfRangeException
statusor the status of an index isUnknown, which has no name on the wire, or not a member of its enum.
TableCreated(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>)
Creates the answer to a CreateTable: the description of Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>) under TableDescription, with the status CREATING.
An emulator answers with a table that is ACTIVE already, for which a test passes that status.
public static StubResponse TableCreated(string name, TableStatus status = TableStatus.Creating, params ReadOnlySpan<GlobalSecondaryIndexDescription> globalIndexes)
Parameters
namestringThe table name.
statusTableStatusThe status of the table.
globalIndexesReadOnlySpan<GlobalSecondaryIndexDescription>The global secondary indexes, as GlobalIndex(string, IndexStatus) makes them. DynamoDB reports them as
CREATINGhere.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
nameis null.- ArgumentOutOfRangeException
statusor the status of an index isUnknown, which has no name on the wire, or not a member of its enum.
TableDeleted(string)
Creates the answer to a DeleteTable: TableDescription with the status DELETING and only what the example of the API reference holds, because a table that is going away reports no keys and no indexes.
public static StubResponse TableDeleted(string name)
Parameters
namestringThe table name.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
nameis null.
TableUpdated(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>)
Creates the answer to an UpdateTable: the description of Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>) under TableDescription, with the status UPDATING, which is
what DynamoDB sends while it applies the change. What a caller does next is a wait on DescribeTable, so a test queues Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>) after this.
public static StubResponse TableUpdated(string name, TableStatus status = TableStatus.Updating, params ReadOnlySpan<GlobalSecondaryIndexDescription> globalIndexes)
Parameters
namestringThe table name.
statusTableStatusThe status of the table.
globalIndexesReadOnlySpan<GlobalSecondaryIndexDescription>The global secondary indexes, as GlobalIndex(string, IndexStatus) makes them.
Returns
- StubResponse
The response.
Remarks
An index that the update adds is CREATING in the answer of DynamoDB, and the description may still show what the table had before: TableUpdated("Orders", TableStatus.Updating, GlobalIndex("ByCustomer", IndexStatus.Creating)).
The indexes are written as they are given, so the status of each is the one of its GlobalIndex(string, IndexStatus), ACTIVE unless the test says otherwise.
Exceptions
- ArgumentNullException
nameis null.- ArgumentOutOfRangeException
statusor the status of an index isUnknown, which has no name on the wire, or not a member of its enum.
Table<T>(string, TableStatus)
Creates the answer to a DescribeTable of a table an entity lives in: its keys with their types, every global index it declares as active, and its local indexes, as
CreateTableCommand would have created them. A wait for the table ends on this answer.
public static StubResponse Table<T>(string name, TableStatus status = TableStatus.Active) where T : IDynamoDbEntity<T>
Parameters
namestringThe table name.
statusTableStatusThe status of the table.
Returns
- StubResponse
The response.
Type Parameters
TThe entity.
Remarks
A table of a single-table schema has the indexes of all its entities, and this lists those of one. For the others, or for an index that is not active yet, list them by name with Table(string, TableStatus, params ReadOnlySpan<GlobalSecondaryIndexDescription>).
Exceptions
- ArgumentNullException
nameis null.- ArgumentOutOfRangeException
statusis Unknown, which has no name on the wire, or not a member of the enum.
TablesListed(params ReadOnlySpan<string>)
Creates the answer to a ListTables that is the last page: {"TableNames":["Orders","Users"]}. A page that more pages follow is
TablesListed(ReadOnlySpan<string>, string).
public static StubResponse TablesListed(params ReadOnlySpan<string> tableNames)
Parameters
tableNamesReadOnlySpan<string>The names on the page, none for an account without tables.
Returns
- StubResponse
The response.
Remarks
The names are written in the order given. DynamoDB sends them sorted, so a test that reads more than one gives them that way.
Exceptions
- ArgumentNullException
A name is null.
TablesListed(ReadOnlySpan<string>, string)
Creates the answer to a ListTables that more pages follow: {"TableNames":["Orders","Users"],"LastEvaluatedTableName":"Users"}. The caller passes the last name as
ExclusiveStartTableName of the next request, which a test answers with the next page.
public static StubResponse TablesListed(ReadOnlySpan<string> tableNames, string lastEvaluatedTableName)
Parameters
tableNamesReadOnlySpan<string>The names on the page, in the order given.
lastEvaluatedTableNamestringThe name to go on after.
Returns
- StubResponse
The response.
Remarks
DynamoDB gives the last name of the page here; the factory writes what it is given, so a test of a client that goes by it can give another.
Exceptions
- ArgumentNullException
A name or
lastEvaluatedTableNameis null.
TimeToLive(TimeToLiveStatus, string?)
Creates the answer to a DescribeTimeToLive: {"TimeToLiveDescription":{"TimeToLiveStatus":"ENABLED","AttributeName":"expires"}}.
public static StubResponse TimeToLive(TimeToLiveStatus status, string? attributeName = null)
Parameters
statusTimeToLiveStatusThe status. A table that never had time to live is Disabled.
attributeNamestringThe attribute that holds the expiry, or null for none, which is what DynamoDB sends for a disabled table.
Returns
- StubResponse
The response.
Exceptions
- ArgumentOutOfRangeException
statusis Unknown, which has no name on the wire, or not a member of the enum.
TimeToLiveUpdated(bool, string)
Creates the answer to an UpdateTimeToLive, which repeats the specification of the request: {"TimeToLiveSpecification":{"AttributeName":"expires","Enabled":true}}.
public static StubResponse TimeToLiveUpdated(bool enabled, string attributeName)
Parameters
enabledboolWhether the request turned time to live on.
attributeNamestringThe attribute that holds the expiry.
Returns
- StubResponse
The response.
Exceptions
- ArgumentNullException
attributeNameis null.
TransactionCanceled(params ReadOnlySpan<CancellationReason>)
Creates the error of a cancelled transaction from whole reasons: Reason(TransactionFailure), ConditionalCheckFailedReason<T>(T?) for one that holds the item ItemFor(TransactMarker) returns, or a CancellationReason of your own for a code this library does not know.
public static StubResponse TransactionCanceled(params ReadOnlySpan<CancellationReason> reasons)
Parameters
reasonsReadOnlySpan<CancellationReason>The reasons, one per action in the order of the actions.
Returns
- StubResponse
The response: HTTP 400 with
TransactionCanceledException.
TransactionCanceled(params ReadOnlySpan<TransactionFailure>)
Creates the error of a cancelled transaction, with one reason per action in the order of the actions, so that ReasonFor(TransactMarker) finds the
reason of a marker: TransactionCanceled(TransactionFailure.None, TransactionFailure.ConditionalCheckFailed) for a transaction whose second action failed.
public static StubResponse TransactionCanceled(params ReadOnlySpan<TransactionFailure> reasons)
Parameters
reasonsReadOnlySpan<TransactionFailure>The reasons. Reason(TransactionFailure) says what each one sends.
Returns
- StubResponse
The response: HTTP 400 with
TransactionCanceledException.
Exceptions
- ArgumentOutOfRangeException
A reason is Unknown or not a member of the enum.
Unprocessed(string, KeysAndAttributes)
Creates the answer to a BatchGetItem that read nothing and left keys unprocessed, on one table: Unprocessed("Orders", StubResponse.Keys(key)).
public static StubResponse Unprocessed(string tableName, KeysAndAttributes keys)
Parameters
tableNamestringThe table of the keys.
keysKeysAndAttributesThe keys DynamoDB did not get to.
Returns
- StubResponse
The response.
Remarks
DynamoDB sends along how the keys were to be read, and the next round repeats that as it stands. A test that wants to see ConsistentRead or a projection on the next
round sets it: StubResponse.Keys(key) with { ConsistentRead = true }.
Exceptions
- ArgumentNullException
tableNameorkeysis null.
Unprocessed(string, params ReadOnlySpan<WriteRequest>)
Creates the answer to a BatchWriteItem that left writes unprocessed, on one table: Unprocessed("Orders", StubResponse.Put(order), StubResponse.Delete(key)).
Without writes it is the answer that ends a batch. Writes on several tables are a body for Json(string, HttpStatusCode, IReadOnlyDictionary<string, string>?).
public static StubResponse Unprocessed(string tableName, params ReadOnlySpan<WriteRequest> writes)
Parameters
tableNamestringThe table of the writes.
writesReadOnlySpan<WriteRequest>The writes DynamoDB did not get to.
Returns
- StubResponse
The response.
Remarks
The batch sends the writes again by itself, so a test queues what the later rounds get as well, and the wait before a round runs on TimeProvider: see StubHandler.
Exceptions
- ArgumentNullException
tableNameis null.
Unprocessed<T>(string, KeysAndAttributes, IEnumerable<T>)
Creates the answer to a BatchGetItem that read some items and left the other keys unprocessed, on one table.
public static StubResponse Unprocessed<T>(string tableName, KeysAndAttributes keys, IEnumerable<T> found) where T : IDynamoDbDocument<T>
Parameters
tableNamestringThe table of the items and the keys.
keysKeysAndAttributesThe keys DynamoDB did not get to.
foundIEnumerable<T>The items it read.
Returns
- StubResponse
The response.
Type Parameters
TThe type of the items: a generated entity or Item.
Exceptions
- ArgumentNullException
tableName,keysorfoundis null.