Skip to content

Commit f35aaac

Browse files
committed
refactor: update DynamoDB context initialization to use DynamoDBContextBuilder (AWSSDK.DynamoDBv2 v4) and adjust query operation config in tests
1 parent 8f915b4 commit f35aaac

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

Unicorn.Web/ApprovalService.Tests/RequestApprovalFunctionTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public async Task Publish_event_when_property_status_is_pending_or_declined()
3232
.Build();
3333

3434
var context = TestHelpers.NewLambdaContext();
35-
3635
var dynamoDbContext = Substitute.For<IDynamoDBContext>();
3736
var eventBindingClient = Substitute.For<IAmazonEventBridge>();
3837

@@ -72,7 +71,7 @@ public async Task Publish_event_when_property_status_is_pending_or_declined()
7271
};
7372

7473
dynamoDbContext
75-
.FromQueryAsync<PropertyRecord>(Arg.Any<QueryOperationConfig>(), Arg.Any<DynamoDBOperationConfig>())
74+
.FromQueryAsync<PropertyRecord>(Arg.Any<Amazon.DynamoDBv2.DocumentModel.QueryOperationConfig>())
7675
.Returns(TestHelpers.NewDynamoDBSearchResult(searchResult));
7776

7877
eventBindingClient.PutEventsAsync(Arg.Any<PutEventsRequest>(), Arg.Any<CancellationToken>())
@@ -84,7 +83,7 @@ public async Task Publish_event_when_property_status_is_pending_or_declined()
8483

8584
// Assert
8685
dynamoDbContext.Received(1)
87-
.FromQueryAsync<PropertyRecord>(Arg.Any<QueryOperationConfig>(), Arg.Any<DynamoDBOperationConfig>());
86+
.FromQueryAsync<PropertyRecord>(Arg.Any<Amazon.DynamoDBv2.DocumentModel.QueryOperationConfig>());
8887

8988
await eventBindingClient.Received(1)
9089
.PutEventsAsync(
@@ -136,11 +135,11 @@ public async Task Do_not_publish_event_when_property_status_is_approved()
136135
// Assert
137136

138137
dynamoDbContext
139-
.FromQueryAsync<PropertyRecord>(Arg.Any<QueryOperationConfig>(), Arg.Any<DynamoDBOperationConfig>())
138+
.FromQueryAsync<PropertyRecord>(Arg.Any<Amazon.DynamoDBv2.DocumentModel.QueryOperationConfig>())
140139
.Returns(TestHelpers.NewDynamoDBSearchResult(searchResult));
141140

142141
dynamoDbContext.Received(1)
143-
.FromQueryAsync<PropertyRecord>(Arg.Any<QueryOperationConfig>(), Arg.Any<DynamoDBOperationConfig>());
142+
.FromQueryAsync<PropertyRecord>(Arg.Any<Amazon.DynamoDBv2.DocumentModel.QueryOperationConfig>());
144143

145144
eventBindingClient.PutEventsAsync(Arg.Any<PutEventsRequest>(), Arg.Any<CancellationToken>())
146145
.Returns(new PutEventsResponse { FailedEntryCount = 0 });

Unicorn.Web/ApprovalService/PublicationApprovedEventHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public PublicationApprovedEventHandler()
3636
AWSConfigsDynamoDB.Context.TypeMappings[typeof(PropertyRecord)] =
3737
new TypeMapping(typeof(PropertyRecord), dynamodbTable);
3838

39-
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
40-
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
39+
_dynamoDbContext = new DynamoDBContextBuilder()
40+
.ConfigureContext(c => c.Conversion=DynamoDBEntryConversion.V2)
41+
.Build();
4142
}
4243

4344
/// <summary>

Unicorn.Web/ApprovalService/RequestApprovalFunction.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ public RequestApprovalFunction()
4848
// Initialise DDB client
4949
AWSConfigsDynamoDB.Context.TypeMappings[typeof(PropertyRecord)] =
5050
new TypeMapping(typeof(PropertyRecord), _dynamodbTable);
51-
var config = new DynamoDBContextConfig { Conversion = DynamoDBEntryConversion.V2 };
52-
_dynamoDbContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);
51+
52+
_dynamoDbContext = new DynamoDBContextBuilder()
53+
.ConfigureContext(c => c.Conversion=DynamoDBEntryConversion.V2)
54+
.Build();
5355

5456
// Initialise EventBridge client
5557
_eventBindingClient = new AmazonEventBridgeClient();

Unicorn.Web/SearchService.Tests/PropertySearchFunctionTest.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public async Task PropertySearchFunction_SearchByStreet_ReturnsResults()
2525
// Arrange
2626
var request = TestHelpers.LoadApiGatewayProxyRequest("./events/search_by_street_event.json");
2727
var context = TestHelpers.NewLambdaContext();
28-
28+
var dynamoDbContext = Substitute.For<IDynamoDBContext>();
29+
2930
var searchResult = new List<PropertyRecord>
3031
{
3132
new()
@@ -44,8 +45,8 @@ public async Task PropertySearchFunction_SearchByStreet_ReturnsResults()
4445
}
4546
};
4647

47-
var mockDynamoDbContext = Substitute.For<IDynamoDBContext>();
48-
mockDynamoDbContext.FromQueryAsync<PropertyRecord>(Arg.Any<QueryOperationConfig>(), Arg.Any<DynamoDBOperationConfig>())
48+
dynamoDbContext
49+
.FromQueryAsync<PropertyRecord>(Arg.Any<Amazon.DynamoDBv2.DocumentModel.QueryOperationConfig>())
4950
.Returns(TestHelpers.NewDynamoDBSearchResult(searchResult));
5051

5152
var expectedResponse = new APIGatewayProxyResponse
@@ -59,16 +60,16 @@ public async Task PropertySearchFunction_SearchByStreet_ReturnsResults()
5960
};
6061

6162
// Act
62-
var function = new PropertySearchFunction(mockDynamoDbContext);
63+
var function = new PropertySearchFunction(dynamoDbContext);
6364
var response = await function.FunctionHandler(request, context);
6465

6566
// Assert
6667
Assert.Equal(expectedResponse.Headers, response.Headers);
6768
Assert.Equal(expectedResponse.StatusCode, response.StatusCode);
6869
Assert.NotEmpty(response.Body);
6970

70-
mockDynamoDbContext.Received(1)
71-
.FromQueryAsync<PropertyRecord>(Arg.Any<QueryOperationConfig>(), Arg.Any<DynamoDBOperationConfig>());
71+
dynamoDbContext.Received(1)
72+
.FromQueryAsync<PropertyRecord>(Arg.Any<Amazon.DynamoDBv2.DocumentModel.QueryOperationConfig>());
7273

7374
var items = JsonSerializer.Deserialize<List<PropertyDto>>(response.Body);
7475
Assert.NotNull(items);

0 commit comments

Comments
 (0)