添加 RemoveTest 测试方法并更新 EventInfo 类

在 `HashTest.cs` 文件中,新增了 `RemoveTest` 方法,用于测试从 Redis 哈希中移除元素的功能。该方法验证了移除操作后剩余元素的数量。同时,将 `EventInfo` 类的属性类型从可空字符串 (`String?`) 修改为非可空字符串 (`String`)。
This commit is contained in:
猿人易 2025-03-19 11:49:17 +08:00
parent f5bb807a37
commit 9ae8e89ed2
1 changed files with 25 additions and 2 deletions

View File

@ -112,10 +112,33 @@ public class HashTest
rh["0"] = new EventInfo { EventId = "1234", EventName = "Stone" }; rh["0"] = new EventInfo { EventId = "1234", EventName = "Stone" };
} }
[Fact]
public void RemoveTest()
{
var key = $"NewLife:eventinfo:adsfasdfasdfdsaf";
var hash = _redis.GetDictionary<EventInfo>(key);
Assert.NotNull(hash);
var rh = hash as RedisHash<String, EventInfo>;
foreach (var item in rh.GetAll())
{
XTrace.WriteLine(item.Key);
}
rh["0"] = new EventInfo { EventId = "1234", EventName = "Stone" };
rh["1"] = new EventInfo { EventId = "12345", EventName = "Stone" };
rh["2"] = new EventInfo { EventId = "123456", EventName = "Stone" };
rh.Remove("0");
Assert.Equal(2, rh.Count);
}
class EventInfo class EventInfo
{ {
public String? EventId { get; set; } public String EventId { get; set; }
public String? EventName { get; set; } public String EventName { get; set; }
} }
} }