0

I am writing Unit test cases for getting the records from Dynamodb. Dynamodb is returning scanResponse. I want to fake ScanResponse. How to do it?

1 Answers1

2

(I'm assuming you're using the AWSSDK.DynamoDBv2 Nuget package)

You don't fake the ScanResponse; you fake the AmazonDynamoDBClient class (or better, the IAmazonDynamoDB interface; interfaces are less trouble to fake), and you configure its ScanAsync method to return the desired ScanResponse.

var dynamoDb = A.Fake<IAmazonDynamoDb>();
A.CallTo(() => dynamoDb.ScanAsync(A<ScanRequest>._, A<CancellationToken>._))
    .Returns(new ScanResponse
    {
        // Define the ScanResponse you want the method to return
        ...
    });
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758