@@ -1154,15 +1154,17 @@ public async Task TestGetIssue198_Async()
1154
1154
}
1155
1155
1156
1156
[ Fact ]
1157
- public void TestSetWithSerializationOption ( )
1157
+ public void TestSetWithSerializationOptions ( )
1158
1158
{
1159
1159
var commands = new JsonCommands ( redisFixture . Redis . GetDatabase ( ) ) ;
1160
1160
var keys = CreateKeyNames ( 1 ) ;
1161
1161
var key = keys [ 0 ] ;
1162
1162
var jsonOptions = new JsonSerializerOptions { IncludeFields = true } ;
1163
1163
var person = new Person { Name = "Developer" , Age = 23 , Birthday = DateTime . Today } ;
1164
+
1164
1165
commands . Set ( key , "$" , person , serializerOptions : jsonOptions ) ;
1165
1166
Person ? result = commands . Get < Person > ( key , serializerOptions : jsonOptions ) ;
1167
+
1166
1168
Assert . NotNull ( result ) ;
1167
1169
Assert . Equal ( person . Name , result ! . Name ) ;
1168
1170
Assert . Equal ( person . Age , result ! . Age ) ;
@@ -1171,19 +1173,58 @@ public void TestSetWithSerializationOption()
1171
1173
}
1172
1174
1173
1175
[ Fact ]
1174
- public async Task TestSetAsyncWithSerializationOption ( )
1176
+ public async Task TestSetWithSerializationOptionsAsync ( )
1175
1177
{
1176
1178
var commands = new JsonCommands ( redisFixture . Redis . GetDatabase ( ) ) ;
1177
1179
var keys = CreateKeyNames ( 1 ) ;
1178
1180
var key = keys [ 0 ] ;
1179
1181
var jsonOptions = new JsonSerializerOptions { IncludeFields = true } ;
1180
1182
var person = new Person { Name = "Developer" , Age = 23 , Birthday = DateTime . Today } ;
1183
+
1181
1184
await commands . SetAsync ( key , "$" , person , serializerOptions : jsonOptions ) ;
1182
1185
Person ? result = await commands . GetAsync < Person > ( key , serializerOptions : jsonOptions ) ;
1186
+
1183
1187
Assert . NotNull ( result ) ;
1184
1188
Assert . Equal ( person . Name , result ! . Name ) ;
1185
1189
Assert . Equal ( person . Age , result ! . Age ) ;
1186
1190
Assert . NotNull ( result ! . Birthday ) ;
1187
1191
Assert . Equal ( person . Birthday , result ! . Birthday ) ;
1188
1192
}
1193
+
1194
+ [ SkipIfRedis ( "7.1.242" ) ]
1195
+ public void MergeWithSerializationOptions ( )
1196
+ {
1197
+ string expected = "{\" age\" :23,\" birthday\" :\" 2023-12-31T00:00:00\" ,\" name\" :\" Developer\" }" ;
1198
+
1199
+ var commands = new JsonCommands ( redisFixture . Redis . GetDatabase ( ) ) ;
1200
+ var keys = CreateKeyNames ( 1 ) ;
1201
+ var key = keys [ 0 ] ;
1202
+ commands . Set ( key , "$" , new { age = 5 , birthday = new DateTime ( 2000 , 1 , 1 ) } ) ;
1203
+
1204
+ var jsonOptions = new JsonSerializerOptions { IncludeFields = true , PropertyNamingPolicy = JsonNamingPolicy . CamelCase } ;
1205
+ var person = new Person { Name = "Developer" , Age = 23 , Birthday = new DateTime ( 2023 , 12 , 31 ) } ;
1206
+ commands . Merge ( key , "$" , person , serializerOptions : jsonOptions ) ;
1207
+ string actual = commands . Get ( key ) . ToString ( ) ;
1208
+
1209
+ Assert . Equal ( expected , actual ) ;
1210
+ }
1211
+
1212
+ [ SkipIfRedis ( "7.1.242" ) ]
1213
+ public async Task MergeWithSerializationOptionsAsync ( )
1214
+ {
1215
+ string expected = "{\" age\" :23,\" birthday\" :\" 2023-12-31T00:00:00\" ,\" name\" :\" Developer\" }" ;
1216
+
1217
+ var commands = new JsonCommands ( redisFixture . Redis . GetDatabase ( ) ) ;
1218
+ var keys = CreateKeyNames ( 1 ) ;
1219
+ var key = keys [ 0 ] ;
1220
+ await commands . SetAsync ( key , "$" , new { age = 5 , birthday = new DateTime ( 2000 , 1 , 1 ) } ) ;
1221
+
1222
+ var jsonOptions = new JsonSerializerOptions { IncludeFields = true , PropertyNamingPolicy = JsonNamingPolicy . CamelCase } ;
1223
+ var person = new Person { Name = "Developer" , Age = 23 , Birthday = new DateTime ( 2023 , 12 , 31 ) } ;
1224
+ await commands . MergeAsync ( key , "$" , person , serializerOptions : jsonOptions ) ;
1225
+ RedisResult rr = await commands . GetAsync ( key ) ;
1226
+ string actual = rr . ToString ( ) ;
1227
+
1228
+ Assert . Equal ( expected , actual ) ;
1229
+ }
1189
1230
}
0 commit comments