添加 RemoveTest 测试方法并更新 EventInfo 类
在 `HashTest.cs` 文件中,新增了 `RemoveTest` 方法,用于测试从 Redis 哈希中移除元素的功能。该方法验证了移除操作后剩余元素的数量。同时,将 `EventInfo` 类的属性类型从可空字符串 (`String?`) 修改为非可空字符串 (`String`)。
This commit is contained in:
parent
f5bb807a37
commit
9ae8e89ed2
|
@ -112,10 +112,33 @@ public class HashTest
|
|||
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
|
||||
{
|
||||
public String? EventId { get; set; }
|
||||
public String? EventName { get; set; }
|
||||
public String EventId { get; set; }
|
||||
public String EventName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue