Skip to content

Commit be26bc6

Browse files
committed
Added tests for Merge and MergeAsync methods.
1 parent 7a648d6 commit be26bc6

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

tests/NRedisStack.Tests/Json/JsonTests.cs

+43-2
Original file line numberDiff line numberDiff line change
@@ -1154,15 +1154,17 @@ public async Task TestGetIssue198_Async()
11541154
}
11551155

11561156
[Fact]
1157-
public void TestSetWithSerializationOption()
1157+
public void TestSetWithSerializationOptions()
11581158
{
11591159
var commands = new JsonCommands(redisFixture.Redis.GetDatabase());
11601160
var keys = CreateKeyNames(1);
11611161
var key = keys[0];
11621162
var jsonOptions = new JsonSerializerOptions { IncludeFields = true };
11631163
var person = new Person { Name = "Developer", Age = 23, Birthday = DateTime.Today };
1164+
11641165
commands.Set(key, "$", person, serializerOptions: jsonOptions);
11651166
Person? result = commands.Get<Person>(key, serializerOptions: jsonOptions);
1167+
11661168
Assert.NotNull(result);
11671169
Assert.Equal(person.Name, result!.Name);
11681170
Assert.Equal(person.Age, result!.Age);
@@ -1171,19 +1173,58 @@ public void TestSetWithSerializationOption()
11711173
}
11721174

11731175
[Fact]
1174-
public async Task TestSetAsyncWithSerializationOption()
1176+
public async Task TestSetWithSerializationOptionsAsync()
11751177
{
11761178
var commands = new JsonCommands(redisFixture.Redis.GetDatabase());
11771179
var keys = CreateKeyNames(1);
11781180
var key = keys[0];
11791181
var jsonOptions = new JsonSerializerOptions { IncludeFields = true };
11801182
var person = new Person { Name = "Developer", Age = 23, Birthday = DateTime.Today };
1183+
11811184
await commands.SetAsync(key, "$", person, serializerOptions: jsonOptions);
11821185
Person? result = await commands.GetAsync<Person>(key, serializerOptions: jsonOptions);
1186+
11831187
Assert.NotNull(result);
11841188
Assert.Equal(person.Name, result!.Name);
11851189
Assert.Equal(person.Age, result!.Age);
11861190
Assert.NotNull(result!.Birthday);
11871191
Assert.Equal(person.Birthday, result!.Birthday);
11881192
}
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+
}
11891230
}

0 commit comments

Comments
 (0)