1
+ using System . Globalization ;
2
+ using Amazon . DynamoDBv2 . DataModel ;
3
+ using Amazon . DynamoDBv2 . Model ;
4
+ using AutoFixture ;
5
+ using DynamoDBGenerator . Attributes ;
6
+ using Dynatello . Builders ;
7
+ using Dynatello . Builders . Types ;
8
+ using FluentAssertions ;
9
+
10
+ namespace Dynatello . Tests ;
11
+
12
+ [ DynamoDBMarshaller ( typeof ( Cat ) , ArgumentType = typeof ( ( Guid Id , double MinimumCuteness ) ) ) ]
13
+ public partial class ToQueryRequestTests
14
+ {
15
+ private readonly Fixture _fixture = new ( ) ;
16
+
17
+ public ToQueryRequestTests ( )
18
+ {
19
+ _queryCatWithIdAndMinimumCuteness = CatMarshaller
20
+ . OnTable ( "TABLE" )
21
+ . WithKeyConditionExpression ( ( x , y ) => $ "{ x . Id } = { y . Id } ")
22
+ . WithFilterExpression ( ( x , y ) => $ "{ x . Cuteness } > { y . MinimumCuteness } ")
23
+ . ToQueryRequestBuilder ( ) ;
24
+ }
25
+
26
+ private readonly QueryRequestBuilder < ( Guid Id , double MinimumCuteness ) > _queryCatWithIdAndMinimumCuteness ;
27
+
28
+ [ Fact ]
29
+ public void Test ( )
30
+ {
31
+ _fixture . CreateMany < ( Guid Id , double MinimumCuteness ) > ( 10 ) . Should ( ) . AllSatisfy ( tuple =>
32
+ {
33
+ var request = _queryCatWithIdAndMinimumCuteness . Build ( tuple ) ;
34
+
35
+ request . TableName . Should ( ) . Be ( "TABLE" ) ;
36
+ request . ExpressionAttributeNames . Should ( ) . BeEquivalentTo ( new Dictionary < string , string >
37
+ {
38
+ { "#Id" , nameof ( Cat . Id ) } ,
39
+ { "#Cuteness" , nameof ( Cat . Cuteness ) }
40
+ } ) ;
41
+
42
+ request . ExpressionAttributeValues . Should ( ) . BeEquivalentTo ( new Dictionary < string , AttributeValue >
43
+ {
44
+ { ":p1" , new AttributeValue { S = tuple . Id . ToString ( ) } } ,
45
+ { ":p2" , new AttributeValue { N = tuple . MinimumCuteness . ToString ( CultureInfo . InvariantCulture ) } }
46
+ } ) ;
47
+
48
+ request . KeyConditionExpression . Should ( ) . Be ( "#Id = :p1" ) ;
49
+ request . FilterExpression . Should ( ) . Be ( "#Cuteness > :p2" ) ;
50
+ } ) ;
51
+ }
52
+ }
53
+
54
+ public record Cat (
55
+ [ property: DynamoDBHashKey ] Guid Id ,
56
+ [ property: DynamoDBRangeKey ] Guid HomeId ,
57
+ string Name ,
58
+ double Cuteness ) ;
0 commit comments