public async Task DynamoDbService_Should_List_Records_In_A_DynamoDb_Table() { var tableName = Guid.NewGuid().ToString(); const int recordCount = 5; var dynamoDbOperationConfig = new DynamoDBOperationConfig() { OverrideTableName = tableName }; await CreateTestTable(tableName); Table targetTable = DynamoDbContext.GetTargetTable <MovieEntity>(dynamoDbOperationConfig); IList <MovieEntity> movieEntities = new Fixture().CreateMany <MovieEntity>(recordCount).ToList(); List <Document> documents = movieEntities .Select(entity => { string serialize = JsonSerializer.Serialize(entity); Document item = Document.FromJson(serialize); return(item); }) .ToList(); foreach (Document document in documents) { await targetTable.PutItemAsync(document); } dynamoDbOperationConfig.IndexName = TestConstants.MoiveTableMovieIdGsi; List <MovieEntity> returnedMovieEntities = await DynamoDbContext.ScanAsync <MovieEntity>(new List <ScanCondition>(), dynamoDbOperationConfig).GetRemainingAsync(); Assert.NotNull(movieEntities); Assert.NotEmpty(movieEntities); Assert.Equal(recordCount, movieEntities.Count); Assert.All(returnedMovieEntities, movieEntity => { MovieEntity entity = movieEntities.First(e => e.MovieId == movieEntity.MovieId); Assert.True(movieEntity.DeepEquals(entity)); }); }
public async Task DynamoDbService_Should_Add_A_Record_To_A_DynamoDb_Table() { var tableName = Guid.NewGuid().ToString(); var dynamoDbOperationConfig = new DynamoDBOperationConfig() { OverrideTableName = tableName }; await CreateTestTable(tableName); Table targetTable = DynamoDbContext.GetTargetTable <MovieEntity>(dynamoDbOperationConfig); var movieEntity = new Fixture().Create <MovieEntity>(); string modelJson = JsonSerializer.Serialize(movieEntity); Document item = Document.FromJson(modelJson); await targetTable.PutItemAsync(item); dynamoDbOperationConfig.IndexName = TestConstants.MoiveTableMovieIdGsi; List <MovieEntity> movieEntities = await DynamoDbContext.QueryAsync <MovieEntity>(movieEntity.MovieId, dynamoDbOperationConfig).GetRemainingAsync(); Assert.True(movieEntity.DeepEquals(movieEntities.First())); }