Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 5530982

Browse files
committed
Add Redis Typed Hash test
1 parent d035c23 commit 5530982

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/ServiceStack.Redis.Tests/Issues/ReportedIssues.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23
using NUnit.Framework;
4+
using ServiceStack.Redis.Generic;
5+
using ServiceStack.Text;
36

47
namespace ServiceStack.Redis.Tests.Issues
58
{
@@ -49,5 +52,60 @@ public void Success_callback_fails_for_pipeline_using_GetItemScoreInSortedSet()
4952

5053
Assert.That(score, Is.EqualTo(1));
5154
}
55+
56+
public class Test
57+
{
58+
public int Id { get; set; }
59+
public string Name { get; set; }
60+
61+
protected bool Equals(Test other) => Id == other.Id && Name == other.Name;
62+
63+
public override bool Equals(object obj)
64+
{
65+
if (ReferenceEquals(null, obj)) return false;
66+
if (ReferenceEquals(this, obj)) return true;
67+
if (obj.GetType() != this.GetType()) return false;
68+
return Equals((Test) obj);
69+
}
70+
71+
public override int GetHashCode()
72+
{
73+
unchecked
74+
{
75+
return (Id * 397) ^ (Name != null ? Name.GetHashCode() : 0);
76+
}
77+
}
78+
}
79+
80+
[Test]
81+
public void Try_simulate_NRE_when_calling_GetAllEntriesFromHash_using_BasicRedisClientManager()
82+
{
83+
using (var redisManager = new BasicRedisClientManager(TestConfig.SingleHost))
84+
using (var redis = redisManager.GetClient())
85+
{
86+
IRedisHash<string, Test> testHash = redis.As<Test>()
87+
.GetHash<string>("test-hash");
88+
89+
Assert.That(testHash.Count, Is.EqualTo(0));
90+
91+
var contents = testHash.GetAll();
92+
Assert.That(contents.Count, Is.EqualTo(0));
93+
94+
var test1 = new Test { Id = 1, Name = "Name1" };
95+
var test2 = new Test { Id = 2, Name = "Name2" };
96+
testHash["A"] = test1;
97+
testHash["B"] = test2;
98+
99+
contents = testHash.GetAll();
100+
101+
Assert.That(contents, Is.EqualTo(new Dictionary<string, Test> {
102+
["A"] = test1,
103+
["B"] = test2,
104+
}));
105+
106+
Assert.That(testHash["A"], Is.EqualTo(test1));
107+
Assert.That(testHash["B"], Is.EqualTo(test2));
108+
}
109+
}
52110
}
53111
}

0 commit comments

Comments
 (0)