@@ -1152,4 +1152,79 @@ public async Task TestGetIssue198_Async()
1152
1152
Assert . Null ( result ) ;
1153
1153
Assert . Null ( result2 ) ;
1154
1154
}
1155
+
1156
+ [ Fact ]
1157
+ public void TestSetWithSerializationOptions ( )
1158
+ {
1159
+ var commands = new JsonCommands ( redisFixture . Redis . GetDatabase ( ) ) ;
1160
+ var keys = CreateKeyNames ( 1 ) ;
1161
+ var key = keys [ 0 ] ;
1162
+ var jsonOptions = new JsonSerializerOptions { IncludeFields = true } ;
1163
+ var person = new Person { Name = "Developer" , Age = 23 , Birthday = DateTime . Today } ;
1164
+
1165
+ commands . Set ( key , "$" , person , serializerOptions : jsonOptions ) ;
1166
+ Person ? result = commands . Get < Person > ( key , serializerOptions : jsonOptions ) ;
1167
+
1168
+ Assert . NotNull ( result ) ;
1169
+ Assert . Equal ( person . Name , result ! . Name ) ;
1170
+ Assert . Equal ( person . Age , result ! . Age ) ;
1171
+ Assert . NotNull ( result ! . Birthday ) ;
1172
+ Assert . Equal ( person . Birthday , result ! . Birthday ) ;
1173
+ }
1174
+
1175
+ [ Fact ]
1176
+ public async Task TestSetWithSerializationOptionsAsync ( )
1177
+ {
1178
+ var commands = new JsonCommands ( redisFixture . Redis . GetDatabase ( ) ) ;
1179
+ var keys = CreateKeyNames ( 1 ) ;
1180
+ var key = keys [ 0 ] ;
1181
+ var jsonOptions = new JsonSerializerOptions { IncludeFields = true } ;
1182
+ var person = new Person { Name = "Developer" , Age = 23 , Birthday = DateTime . Today } ;
1183
+
1184
+ await commands . SetAsync ( key , "$" , person , serializerOptions : jsonOptions ) ;
1185
+ Person ? result = await commands . GetAsync < Person > ( key , serializerOptions : jsonOptions ) ;
1186
+
1187
+ Assert . NotNull ( result ) ;
1188
+ Assert . Equal ( person . Name , result ! . Name ) ;
1189
+ Assert . Equal ( person . Age , result ! . Age ) ;
1190
+ Assert . NotNull ( result ! . Birthday ) ;
1191
+ Assert . Equal ( person . Birthday , result ! . Birthday ) ;
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
+ }
1155
1230
}
0 commit comments