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

Commit 05ef270

Browse files
committed
Add examples of using complex types with new Custom API's
1 parent 1207ec9 commit 05ef270

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed
Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
using System;
22
using System.Linq;
3-
using System.Threading;
43
using NUnit.Framework;
4+
using ServiceStack.Common.Tests.Models;
5+
using ServiceStack.Redis.Tests;
56
using ServiceStack.Text;
67

78
namespace ServiceStack.Redis
89
{
910
[TestFixture]
1011
public class CustomCommandTests
12+
: RedisClientTestsBase
1113
{
1214
[Test]
1315
public void Can_send_custom_commands()
1416
{
15-
var redis = RedisClient.New();
16-
redis.FlushAll();
17+
Redis.FlushAll();
1718

1819
RedisText ret;
1920

20-
ret = redis.Custom("SET", "foo", 1);
21+
ret = Redis.Custom("SET", "foo", 1);
2122
Assert.That(ret.Text, Is.EqualTo("OK"));
22-
ret = redis.Custom(Commands.Set, "bar", "b");
23+
ret = Redis.Custom(Commands.Set, "bar", "b");
2324

24-
ret = redis.Custom("GET", "foo");
25+
ret = Redis.Custom("GET", "foo");
2526
Assert.That(ret.Text, Is.EqualTo("1"));
26-
ret = redis.Custom(Commands.Get, "bar");
27+
ret = Redis.Custom(Commands.Get, "bar");
2728
Assert.That(ret.Text, Is.EqualTo("b"));
2829

29-
ret = redis.Custom(Commands.Keys, "*");
30+
ret = Redis.Custom(Commands.Keys, "*");
3031
var keys = ret.GetResults();
3132
Assert.That(keys, Is.EquivalentTo(new[] { "foo", "bar" }));
3233

33-
ret = redis.Custom("MGET", "foo", "bar");
34+
ret = Redis.Custom("MGET", "foo", "bar");
3435
var values = ret.GetResults();
3536
Assert.That(values, Is.EquivalentTo(new[] { "1", "b" }));
3637

3738
Enum.GetNames(typeof(DayOfWeek)).ToList()
38-
.ForEach(x => redis.Custom("RPUSH", "DaysOfWeek", x));
39+
.ForEach(x => Redis.Custom("RPUSH", "DaysOfWeek", x));
3940

40-
ret = redis.Custom("LRANGE", "DaysOfWeek", 1, -2);
41+
ret = Redis.Custom("LRANGE", "DaysOfWeek", 1, -2);
4142

4243
var weekDays = ret.GetResults();
4344
Assert.That(weekDays, Is.EquivalentTo(
@@ -46,5 +47,29 @@ public void Can_send_custom_commands()
4647
ret.PrintDump();
4748
}
4849

50+
[Test]
51+
public void Can_send_complex_types_in_Custom_Commands()
52+
{
53+
Redis.FlushAll();
54+
55+
RedisText ret;
56+
57+
ret = Redis.Custom("SET", "foo", new Poco { Name = "Bar" });
58+
Assert.That(ret.Text, Is.EqualTo("OK"));
59+
60+
ret = Redis.Custom("GET", "foo");
61+
var dto = ret.GetResult<Poco>();
62+
Assert.That(dto.Name, Is.EqualTo("Bar"));
63+
64+
Enum.GetNames(typeof(DayOfWeek)).ToList()
65+
.ForEach(x => Redis.Custom("RPUSH", "DaysOfWeek", new Poco { Name = x }));
66+
67+
ret = Redis.Custom("LRANGE", "DaysOfWeek", 1, -2);
68+
var weekDays = ret.GetResults<Poco>();
69+
70+
Assert.That(weekDays.First().Name, Is.EqualTo("Monday"));
71+
72+
ret.PrintDump();
73+
}
4974
}
5075
}

0 commit comments

Comments
 (0)