1
- using Amazon . DynamoDBv2 . DataModel ;
1
+ using Amazon . DynamoDBv2 ;
2
+ using Amazon . DynamoDBv2 . DataModel ;
3
+ using Amazon . DynamoDBv2 . Model ;
2
4
using Microsoft . VisualStudio . TestTools . UnitTesting ;
5
+ using Moq ;
3
6
4
7
namespace AWSSDK_DotNet . UnitTests
5
8
{
6
9
/// <summary>
7
- /// These tests serve as a reminder to developers and reviewers to
8
- /// ensure that new DynamoDB operation-specific properties are plumbed
10
+ /// These tests that new DynamoDB operation-specific properties are plumbed
9
11
/// into the internal code paths correctly
10
12
/// </summary>
11
13
[ TestClass ]
@@ -27,6 +29,30 @@ public void BatchGetConfig()
27
29
Assert . AreEqual ( 8 , typeof ( BatchGetConfig ) . GetProperties ( ) . Length ) ;
28
30
}
29
31
32
+ [ TestMethod ]
33
+ public void BatchGetConfig_OverridesTableName ( )
34
+ {
35
+ var mockClient = new Mock < IAmazonDynamoDB > ( ) ;
36
+ mockClient . Setup ( client => client . BatchGetItem ( It . Is < BatchGetItemRequest > ( request => request . RequestItems . ContainsKey ( "OperationPrefix-TableName" ) ) ) )
37
+ . Returns ( new BatchGetItemResponse { Responses = new ( ) , UnprocessedKeys = new ( ) } )
38
+ . Verifiable ( ) ;
39
+
40
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
41
+ var context = new DynamoDBContext ( mockClient . Object , new DynamoDBContextConfig {
42
+ TableNamePrefix = "ContextPrefix-" ,
43
+ DisableFetchingTableMetadata = true
44
+ } ) ;
45
+
46
+ var batchGetConfig = new BatchGetConfig ( ) { TableNamePrefix = "OperationPrefix-" } ;
47
+
48
+ var batchGet = context . CreateBatchGet < DataModel > ( batchGetConfig ) ;
49
+ batchGet . AddKey ( "123" ) ;
50
+ batchGet . Execute ( ) ;
51
+
52
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
53
+ mockClient . VerifyAll ( ) ;
54
+ }
55
+
30
56
[ TestMethod ]
31
57
public void BatchWriteConfig ( )
32
58
{
@@ -35,6 +61,31 @@ public void BatchWriteConfig()
35
61
Assert . AreEqual ( 8 , typeof ( BatchWriteConfig ) . GetProperties ( ) . Length ) ;
36
62
}
37
63
64
+ [ TestMethod ]
65
+ public void BatchWriteConfig_OverridesTableName ( )
66
+ {
67
+ var mockClient = new Mock < IAmazonDynamoDB > ( ) ;
68
+ mockClient . Setup ( x => x . BatchWriteItem ( It . Is < BatchWriteItemRequest > ( x => x . RequestItems . ContainsKey ( "OperationPrefix-TableName" ) ) ) )
69
+ . Returns ( new BatchWriteItemResponse { UnprocessedItems = new ( ) } )
70
+ . Verifiable ( ) ;
71
+
72
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
73
+ var context = new DynamoDBContext ( mockClient . Object , new DynamoDBContextConfig
74
+ {
75
+ TableNamePrefix = "ContextPrefix-" ,
76
+ DisableFetchingTableMetadata = true
77
+ } ) ;
78
+
79
+ var batchWriteConfig = new BatchWriteConfig ( ) { TableNamePrefix = "OperationPrefix-" } ;
80
+
81
+ var batchWrite = context . CreateBatchWrite < DataModel > ( batchWriteConfig ) ;
82
+ batchWrite . AddPutItem ( new DataModel { Id = "123" } ) ;
83
+ batchWrite . Execute ( ) ;
84
+
85
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
86
+ mockClient . VerifyAll ( ) ;
87
+ }
88
+
38
89
[ TestMethod ]
39
90
public void TransactGetConfig ( )
40
91
{
@@ -43,12 +94,69 @@ public void TransactGetConfig()
43
94
Assert . AreEqual ( 7 , typeof ( TransactGetConfig ) . GetProperties ( ) . Length ) ;
44
95
}
45
96
97
+ [ TestMethod ]
98
+ public void TransactGetConfig_OverridesTableName ( )
99
+ {
100
+ var mockClient = new Mock < IAmazonDynamoDB > ( ) ;
101
+ mockClient . Setup ( x => x . TransactGetItems ( It . Is < TransactGetItemsRequest > ( x => x . TransactItems [ 0 ] . Get . TableName == "OperationPrefix-TableName" ) ) )
102
+ . Returns ( new TransactGetItemsResponse { Responses = new ( ) } )
103
+ . Verifiable ( ) ;
104
+
105
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
106
+ var context = new DynamoDBContext ( mockClient . Object , new DynamoDBContextConfig
107
+ {
108
+ TableNamePrefix = "ContextPrefix-" ,
109
+ DisableFetchingTableMetadata = true
110
+ } ) ;
111
+
112
+ var transactGetConfig = new TransactGetConfig ( ) { TableNamePrefix = "OperationPrefix-" } ;
113
+
114
+ var transactGet = context . CreateTransactGet < DataModel > ( transactGetConfig ) ;
115
+ transactGet . AddKey ( "123" ) ;
116
+ transactGet . Execute ( ) ;
117
+
118
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
119
+ mockClient . VerifyAll ( ) ;
120
+ }
121
+
46
122
[ TestMethod ]
47
123
public void TransactWriteConfig ( )
48
124
{
49
125
// If this fails because you've added a property, be sure to add it to
50
126
// `ToDynamoDBOperationConfig` before updating this unit test
51
127
Assert . AreEqual ( 7 , typeof ( TransactWriteConfig ) . GetProperties ( ) . Length ) ;
52
128
}
129
+
130
+ [ TestMethod ]
131
+ public void TransactWriteConfig_OverridesTableName ( )
132
+ {
133
+ var mockClient = new Mock < IAmazonDynamoDB > ( ) ;
134
+ mockClient . Setup ( x => x . TransactWriteItems ( It . Is < TransactWriteItemsRequest > ( x => x . TransactItems [ 0 ] . Update . TableName == "OperationPrefix-TableName" ) ) )
135
+ . Returns ( new TransactWriteItemsResponse ( ) )
136
+ . Verifiable ( ) ;
137
+
138
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
139
+ var context = new DynamoDBContext ( mockClient . Object , new DynamoDBContextConfig
140
+ {
141
+ TableNamePrefix = "ContextPrefix-" ,
142
+ DisableFetchingTableMetadata = true
143
+ } ) ;
144
+
145
+ var transactWriteConfig = new TransactWriteConfig { TableNamePrefix = "OperationPrefix-" } ;
146
+
147
+ var transactWrite = context . CreateTransactWrite < DataModel > ( transactWriteConfig ) ;
148
+ transactWrite . AddSaveItem ( new DataModel { Id = "123" } ) ;
149
+ transactWrite . Execute ( ) ;
150
+
151
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
152
+ mockClient . VerifyAll ( ) ;
153
+ }
154
+
155
+ [ DynamoDBTable ( "TableName" ) ]
156
+ private class DataModel
157
+ {
158
+ [ DynamoDBHashKey ]
159
+ public string Id { get ; set ; }
160
+ }
53
161
}
54
162
}
0 commit comments