Table of Contents

Class StubResponse

Namespace
DynaSharp.Testing
Assembly
DynaSharp.Testing.dll

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

string

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

IReadOnlyDictionary<string, string>

StatusCode

Gets the HTTP status code. Defaults to OK.

public HttpStatusCode StatusCode { get; init; }

Property Value

HttpStatusCode

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

attributes T

The attributes, or null for none.

Returns

StubResponse

The response.

Type Parameters

T

The 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

tableName string

The table of the items.

items IEnumerable<T>

The items, which may be none.

Returns

StubResponse

The response.

Type Parameters

T

The type of the items: a generated entity or Item.

Exceptions

ArgumentNullException

tableName or items is 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

eventName OperationType

What happened to the item.

keys Item

The key attributes, as KeyOf<T>(T) makes them from an entity.

oldImage Item

The item before the change, or null for none.

newImage Item

The item after the change, or null for none.

sequenceNumber string

The sequence number, or null for one from the position in the page.

Returns

ChangeRecord

The record.

Exceptions

ArgumentNullException

keys is 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

item T

The item, or null if none existed under the key.

Returns

CancellationReason

The reason.

Type Parameters

T

The 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

item T

The item, or null if none existed under the key.

Returns

StubResponse

The response: HTTP 400 with ConditionalCheckFailedException.

Type Parameters

T

The 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

count int

How many items are in the page after the filter.

lastEvaluatedKey Item

The key of the last item DynamoDB read, as KeyOf<T>(T) makes it from an entity.

scannedCount int?

How many items DynamoDB read before the filter, or null for count.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

lastEvaluatedKey is null.

ArgumentOutOfRangeException

count is negative, or scannedCount is 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

count int

How many items are in the page after the filter.

lastEvaluatedKey IKey

The key of the last item DynamoDB read.

scannedCount int?

How many items DynamoDB read before the filter, or null for count.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

lastEvaluatedKey is null.

ArgumentOutOfRangeException

count is negative, or scannedCount is 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

count int

How many items are in the page after the filter.

scannedCount int?

How many items DynamoDB read before the filter, or null for count.

Returns

StubResponse

The response.

Exceptions

ArgumentOutOfRangeException

count is negative, or scannedCount is below it, which DynamoDB never sends.

Delete(Item)

public static WriteRequest Delete(Item key)

Parameters

key Item

The attributes of the key, as KeyOf<T>(T) makes them from an entity.

Returns

WriteRequest

The write.

Exceptions

ArgumentNullException

key is null.

Delete(IKey)

Creates a delete by a generated key for Unprocessed(string, params ReadOnlySpan<WriteRequest>).

public static WriteRequest Delete(IKey key)

Parameters

key IKey

The key.

Returns

WriteRequest

The write.

Exceptions

ArgumentNullException

key is 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

errorCode string

The error code without namespace, for example ResourceNotFoundException or ThrottlingException.

message string

The error message.

statusCode HttpStatusCode

The HTTP status code. DynamoDB answers client errors with 400 and server errors with 500.

requestId string

The value of the x-amzn-RequestId header, 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

indexName string

The name of the index.

status IndexStatus

The status of the index.

Returns

GlobalSecondaryIndexDescription

The index.

Exceptions

ArgumentNullException

indexName is 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

newImage T

The item, written as it is stored, and the source of the key.

sequenceNumber string

The sequence number, or null for one from the position in the page.

Returns

ChangeRecord

The record.

Type Parameters

T

The entity. Change(OperationType, Item, Item?, Item?, string?) takes an Item, which does not say what its key is.

Exceptions

ArgumentNullException

newImage is 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

item T

The 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

T

The 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

items IEnumerable<T>

The items, which may be none.

lastEvaluatedKey Item

The key of the last item DynamoDB read, as KeyOf<T>(T) makes it from an entity.

scannedCount int?

How many items DynamoDB read before the filter, or null for as many as items holds.

Returns

StubResponse

The response.

Type Parameters

T

The type of the items: a generated entity or Item.

Exceptions

ArgumentNullException

items or lastEvaluatedKey is null.

ArgumentOutOfRangeException

scannedCount is 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

items IEnumerable<T>

The items, which may be none.

lastEvaluatedKey IKey

The key of the last item DynamoDB read.

scannedCount int?

How many items DynamoDB read before the filter, or null for as many as items holds.

Returns

StubResponse

The response.

Type Parameters

T

The type of the items: a generated entity or Item.

Exceptions

ArgumentNullException

items or lastEvaluatedKey is null.

ArgumentOutOfRangeException

scannedCount is 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

items IEnumerable<T>

The items, which may be none.

scannedCount int?

How many items DynamoDB read before the filter, or null for as many as items holds.

Returns

StubResponse

The response.

Type Parameters

T

The 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

items is null.

ArgumentOutOfRangeException

scannedCount is 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

json string

The body, for example {"Item":{"pk":{"S":"a"}}}.

statusCode HttpStatusCode

The HTTP status code. DynamoDB answers successful requests with 200.

headers IReadOnlyDictionary<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

key IKey

The key.

Returns

Item

A new item that holds the key attributes.

Exceptions

ArgumentNullException

key is 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

entity T

The entity.

Returns

Item

A new item that holds the key attributes.

Type Parameters

T

The type of the entity.

Exceptions

ArgumentNullException

entity is null.

Keys(params ReadOnlySpan<Item>)

public static KeysAndAttributes Keys(params ReadOnlySpan<Item> keys)

Parameters

keys ReadOnlySpan<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

keys ReadOnlySpan<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

oldImage T

The item before the change.

newImage T

The item after the change, and the source of the key.

sequenceNumber string

The sequence number, or null for one from the position in the page.

Returns

ChangeRecord

The record.

Type Parameters

T

The entity. Change(OperationType, Item, Item?, Item?, string?) takes an Item, which does not say what its key is.

Exceptions

ArgumentNullException

oldImage or newImage is null.

Put<T>(T)

public static WriteRequest Put<T>(T item) where T : IDynamoDbDocument<T>

Parameters

item T

The item.

Returns

WriteRequest

The write.

Type Parameters

T

The type of the item: a generated entity or Item.

Exceptions

ArgumentNullException

item is 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

failure TransactionFailure

The failure.

Returns

CancellationReason

The reason.

Exceptions

ArgumentOutOfRangeException

failure is 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

nextShardIterator string

The 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.

records ReadOnlySpan<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

oldImage T

The item before the delete, and the source of the key.

sequenceNumber string

The sequence number, or null for one from the position in the page.

Returns

ChangeRecord

The record.

Type Parameters

T

The entity. Change(OperationType, Item, Item?, Item?, string?) takes an Item, which does not say what its key is.

Exceptions

ArgumentNullException

oldImage is 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

shardId string

The id of the shard, which a GetShardIterator names.

parentShardId string

The shard this one split from, or null for a shard without a parent.

endingSequenceNumber string

The last sequence number of a closed shard, or null for an open one.

Returns

Shard

The shard.

Exceptions

ArgumentNullException

shardId is null.

ShardIterator(string)

Creates the answer to a GetShardIterator: {"ShardIterator":"..."}.

public static StubResponse ShardIterator(string iterator)

Parameters

iterator string

The iterator, which a GetRecords of the test then sends.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

iterator is 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

description StreamDescription

The description.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

description is 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

tableName string

The table of the stream.

status StreamStatus

The status of the stream. Unknown sends none.

shards ReadOnlySpan<Shard>

The shards, as Shard(string, string?, string?) makes them.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

tableName is 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

tableName string

The table of the stream.

shards ReadOnlySpan<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

tableName is 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

name string

The table name.

status TableStatus

The status of the table.

globalIndexes ReadOnlySpan<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

name is null.

ArgumentOutOfRangeException

status or the status of an index is Unknown, 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

name string

The table name.

status TableStatus

The status of the table.

globalIndexes ReadOnlySpan<GlobalSecondaryIndexDescription>

The global secondary indexes, as GlobalIndex(string, IndexStatus) makes them. DynamoDB reports them as CREATING here.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

name is null.

ArgumentOutOfRangeException

status or the status of an index is Unknown, 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

name string

The table name.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

name is 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

name string

The table name.

status TableStatus

The status of the table.

globalIndexes ReadOnlySpan<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

name is null.

ArgumentOutOfRangeException

status or the status of an index is Unknown, 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

name string

The table name.

status TableStatus

The status of the table.

Returns

StubResponse

The response.

Type Parameters

T

The 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

name is null.

ArgumentOutOfRangeException

status is 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

tableNames ReadOnlySpan<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

tableNames ReadOnlySpan<string>

The names on the page, in the order given.

lastEvaluatedTableName string

The 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 lastEvaluatedTableName is 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

status TimeToLiveStatus

The status. A table that never had time to live is Disabled.

attributeName string

The attribute that holds the expiry, or null for none, which is what DynamoDB sends for a disabled table.

Returns

StubResponse

The response.

Exceptions

ArgumentOutOfRangeException

status is 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

enabled bool

Whether the request turned time to live on.

attributeName string

The attribute that holds the expiry.

Returns

StubResponse

The response.

Exceptions

ArgumentNullException

attributeName is 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

reasons ReadOnlySpan<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

reasons ReadOnlySpan<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

tableName string

The table of the keys.

keys KeysAndAttributes

The 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

tableName or keys is 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

tableName string

The table of the writes.

writes ReadOnlySpan<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

tableName is 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

tableName string

The table of the items and the keys.

keys KeysAndAttributes

The keys DynamoDB did not get to.

found IEnumerable<T>

The items it read.

Returns

StubResponse

The response.

Type Parameters

T

The type of the items: a generated entity or Item.

Exceptions

ArgumentNullException

tableName, keys or found is null.