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

Commit a152e52

Browse files
committed
Add Test to create test data
1 parent 8b994a6 commit a152e52

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using NUnit.Framework;
4+
5+
namespace ServiceStack.Redis.Tests.Examples
6+
{
7+
[TestFixture, Explicit]
8+
public class TestData
9+
: RedisClientTestsBase
10+
{
11+
public class Article
12+
{
13+
public int Id { get; set; }
14+
public string Title { get; set; }
15+
public DateTime ModifiedDate { get; set; }
16+
}
17+
18+
[Test]
19+
public void Create_test_data_for_all_types()
20+
{
21+
AddLists();
22+
AddSets();
23+
AddSortedSets();
24+
AddHashes();
25+
}
26+
27+
private void AddLists()
28+
{
29+
var storeMembers = new List<string> { "one", "two", "three", "four" };
30+
storeMembers.ForEach(x => Redis.AddItemToList("testlist", x));
31+
}
32+
33+
private void AddSets()
34+
{
35+
var storeMembers = new List<string> { "one", "two", "three", "four" };
36+
storeMembers.ForEach(x => Redis.AddItemToSet("testset", x));
37+
}
38+
39+
private void AddHashes()
40+
{
41+
var stringMap = new Dictionary<string, string> {
42+
{"one","a"}, {"two","b"}, {"three","c"}, {"four","d"}
43+
};
44+
var stringIntMap = new Dictionary<string, int> {
45+
{"one",1}, {"two",2}, {"three",3}, {"four",4}
46+
};
47+
48+
stringMap.Each(x => Redis.SetEntryInHash("testhash", x.Key, x.Value));
49+
50+
var hash = Redis.Hashes["testhash"];
51+
stringIntMap.Each(x => hash.Add(x.Key, x.Value.ToString()));
52+
}
53+
54+
private void AddSortedSets()
55+
{
56+
var i = 0;
57+
var storeMembers = new List<string> { "one", "two", "three", "four" };
58+
storeMembers.ForEach(x => Redis.AddItemToSortedSet("testzset", x, i++));
59+
60+
var redisArticles = Redis.As<Article>();
61+
62+
var articles = new[]
63+
{
64+
new Article {Id = 1, Title = "Article 1", ModifiedDate = new DateTime(2015, 01, 02)},
65+
new Article {Id = 2, Title = "Article 2", ModifiedDate = new DateTime(2015, 01, 01)},
66+
new Article {Id = 3, Title = "Article 3", ModifiedDate = new DateTime(2015, 01, 03)},
67+
};
68+
69+
redisArticles.StoreAll(articles);
70+
71+
const string LatestArticlesSet = "urn:Article:modified";
72+
73+
foreach (var article in articles)
74+
{
75+
Redis.AddItemToSortedSet(LatestArticlesSet, article.Id.ToString(), article.ModifiedDate.Ticks);
76+
}
77+
}
78+
}
79+
}

tests/ServiceStack.Redis.Tests/ServiceStack.Redis.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<Compile Include="AdhocClientTests.cs" />
184184
<Compile Include="ConfigTests.cs" />
185185
<Compile Include="CustomCommandTests.cs" />
186+
<Compile Include="Examples\TestData.cs" />
186187
<Compile Include="Issues\RedisCharacterizationTests.cs" />
187188
<Compile Include="RedisBatchTests.cs" />
188189
<Compile Include="RedisManagerPoolTests.cs" />

0 commit comments

Comments
 (0)