From 9ae8e89ed2fc9d34dcdd4c7e5e262d8aac63dcf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=BF=E4=BA=BA=E6=98=93?= Date: Wed, 19 Mar 2025 11:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20RemoveTest=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E6=96=B9=E6=B3=95=E5=B9=B6=E6=9B=B4=E6=96=B0=20EventI?= =?UTF-8?q?nfo=20=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `HashTest.cs` 文件中,新增了 `RemoveTest` 方法,用于测试从 Redis 哈希中移除元素的功能。该方法验证了移除操作后剩余元素的数量。同时,将 `EventInfo` 类的属性类型从可空字符串 (`String?`) 修改为非可空字符串 (`String`)。 --- XUnitTest/HashTest.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/XUnitTest/HashTest.cs b/XUnitTest/HashTest.cs index 760e4eb..bd3e379 100644 --- a/XUnitTest/HashTest.cs +++ b/XUnitTest/HashTest.cs @@ -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(key); + Assert.NotNull(hash); + + var rh = hash as RedisHash; + + 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; } } }