-
Notifications
You must be signed in to change notification settings - Fork 867
Support ScannedCount on DynamoDb Document Model #3751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dscpinheiro
merged 6 commits into
aws:development
from
irina-herciu:issues/2018ScannedCount
Jun 2, 2025
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10ab70b
Support ScannedCount on DynamoDb Document Model
irina-herciu 95bfd64
update unit test proj generation for dynamoDB
irina-herciu f790228
sync with main
irina-herciu 8e927a0
sign all unit test projects
irina-herciu b5767bc
merge from main
irina-herciu 20fc838
add InternalsVisibleTo to AWSSDK.UnitTests.NetFramework for dynamoDB
irina-herciu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
generator/.DevConfigs/778f8bc5-440c-4d7f-8f02-2224fbc2649d.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"services": [ | ||
{ | ||
"serviceName": "DynamoDBv2", | ||
"type": "patch", | ||
"changeLogMessages": [ | ||
"Exposed ScannedCount property on the Search class within the Document Model." | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
sdk/test/Services/DynamoDBv2/UnitTests/Custom/SearchTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using System.Collections.Generic; | ||
using Amazon.DynamoDBv2; | ||
using Amazon.DynamoDBv2.DocumentModel; | ||
using Amazon.DynamoDBv2.Model; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
|
||
namespace AWSSDK_DotNet.UnitTests | ||
{ | ||
[TestClass] | ||
public class SearchTests | ||
{ | ||
private readonly Table _mockTable; | ||
private readonly Mock<IAmazonDynamoDB> _mockDynamoDBClient; | ||
private readonly Search _search; | ||
|
||
public SearchTests() | ||
{ | ||
_mockDynamoDBClient = new Mock<IAmazonDynamoDB>(); | ||
_mockTable = new TableBuilder(_mockDynamoDBClient.Object, "TestTable") | ||
.AddHashKey("Id", DynamoDBEntryType.String).Build(); | ||
|
||
// Initialize Search with mocked dependencies | ||
_search = new Search | ||
{ | ||
SourceTable = _mockTable, | ||
TableName = "TestTable", | ||
CollectResults = true, | ||
Filter = new Filter() | ||
}; | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("DynamoDBv2")] | ||
public void Reset_ShouldResetSearchState() | ||
{ | ||
// Arrange | ||
_search.Matches.Add(new Document()); | ||
|
||
// Act | ||
_search.Reset(); | ||
|
||
// Assert | ||
Assert.AreEqual(0,_search.Matches.Count); | ||
Assert.IsFalse(_search.IsDone); | ||
Assert.IsNull(_search.NextKey); | ||
Assert.IsTrue(_search.CollectResults); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("DynamoDBv2")] | ||
public void GetNextSetHelper_ShouldReturnDocuments() | ||
{ | ||
// Arrange | ||
var mockDocument = new Document(); | ||
var mockScanResponse = new ScanResponse | ||
{ | ||
Items = new List<Dictionary<string, AttributeValue>> { new Dictionary<string, AttributeValue>() }, | ||
LastEvaluatedKey = null, | ||
ScannedCount = 10, | ||
}; | ||
|
||
_mockDynamoDBClient | ||
.Setup(client => client.Scan(It.IsAny<ScanRequest>())) | ||
.Returns(mockScanResponse); | ||
|
||
// Act | ||
var result = _search.GetNextSetHelper(); | ||
|
||
// Assert | ||
Assert.AreEqual(1,result.Count); | ||
Assert.AreEqual(mockDocument, result[0]); | ||
Assert.IsTrue(_search.IsDone); | ||
Assert.AreEqual(10, _search.ScannedCount); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("DynamoDBv2")] | ||
public void GetRemainingHelper_ShouldReturnAllDocuments() | ||
{ | ||
// Arrange | ||
var mockDocument = new Document(); | ||
var mockScanResponse = new ScanResponse | ||
{ | ||
Items = new List<Dictionary<string, AttributeValue>> { new Dictionary<string, AttributeValue>() }, | ||
LastEvaluatedKey = new Dictionary<string, AttributeValue>() | ||
{ | ||
{"test",new AttributeValue("test")} | ||
}, | ||
ScannedCount = 10, | ||
}; | ||
|
||
var mockLastScanResponse = new ScanResponse | ||
{ | ||
Items = new List<Dictionary<string, AttributeValue>> { new Dictionary<string, AttributeValue>() }, | ||
LastEvaluatedKey = null, | ||
ScannedCount = 20, | ||
}; | ||
|
||
_mockDynamoDBClient | ||
.Setup(client => client.Scan(It.Is<ScanRequest>(x=> x.ExclusiveStartKey==null))) | ||
.Returns(mockScanResponse); | ||
|
||
_mockDynamoDBClient | ||
.Setup(client => client.Scan(It.Is<ScanRequest>(x=> x.ExclusiveStartKey != null && x.ExclusiveStartKey.Count==1))) | ||
.Returns(mockLastScanResponse); | ||
|
||
|
||
// Act | ||
var result = _search.GetRemainingHelper(); | ||
|
||
// Assert | ||
Assert.AreEqual(2, result.Count); | ||
Assert.AreEqual(mockDocument, result[0]); | ||
Assert.IsTrue(_search.IsDone); | ||
Assert.AreEqual(30, _search.ScannedCount); | ||
} | ||
|
||
[TestMethod] | ||
[TestCategory("DynamoDBv2")] | ||
public void GetCount_ShouldReturnCorrectCount() | ||
{ | ||
// Arrange// Arrange | ||
var mockScanResponse = new ScanResponse | ||
{ | ||
Items = new List<Dictionary<string, AttributeValue>> { new(), new() }, | ||
LastEvaluatedKey = null, | ||
Count = 2, | ||
ScannedCount = 10, | ||
}; | ||
|
||
_mockDynamoDBClient | ||
.Setup(client => client.Scan(It.IsAny<ScanRequest>())) | ||
.Returns(mockScanResponse); | ||
_search.Reset(); | ||
// Act | ||
var count = _search.Count; | ||
|
||
// Assert | ||
Assert.AreEqual(2, count); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.