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

Commit

Permalink
Add examples of using complex types with new Custom API's
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Oct 14, 2014
1 parent 1207ec9 commit 05ef270
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions tests/ServiceStack.Redis.Tests/CustomCommandTests.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
using System;
using System.Linq;
using System.Threading;
using NUnit.Framework;
using ServiceStack.Common.Tests.Models;
using ServiceStack.Redis.Tests;
using ServiceStack.Text;

namespace ServiceStack.Redis
{
[TestFixture]
public class CustomCommandTests
: RedisClientTestsBase
{
[Test]
public void Can_send_custom_commands()
{
var redis = RedisClient.New();
redis.FlushAll();
Redis.FlushAll();

RedisText ret;

ret = redis.Custom("SET", "foo", 1);
ret = Redis.Custom("SET", "foo", 1);
Assert.That(ret.Text, Is.EqualTo("OK"));
ret = redis.Custom(Commands.Set, "bar", "b");
ret = Redis.Custom(Commands.Set, "bar", "b");

ret = redis.Custom("GET", "foo");
ret = Redis.Custom("GET", "foo");
Assert.That(ret.Text, Is.EqualTo("1"));
ret = redis.Custom(Commands.Get, "bar");
ret = Redis.Custom(Commands.Get, "bar");
Assert.That(ret.Text, Is.EqualTo("b"));

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

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

Enum.GetNames(typeof(DayOfWeek)).ToList()
.ForEach(x => redis.Custom("RPUSH", "DaysOfWeek", x));
.ForEach(x => Redis.Custom("RPUSH", "DaysOfWeek", x));

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

var weekDays = ret.GetResults();
Assert.That(weekDays, Is.EquivalentTo(
Expand All @@ -46,5 +47,29 @@ public void Can_send_custom_commands()
ret.PrintDump();
}

[Test]
public void Can_send_complex_types_in_Custom_Commands()
{
Redis.FlushAll();

RedisText ret;

ret = Redis.Custom("SET", "foo", new Poco { Name = "Bar" });
Assert.That(ret.Text, Is.EqualTo("OK"));

ret = Redis.Custom("GET", "foo");
var dto = ret.GetResult<Poco>();
Assert.That(dto.Name, Is.EqualTo("Bar"));

Enum.GetNames(typeof(DayOfWeek)).ToList()
.ForEach(x => Redis.Custom("RPUSH", "DaysOfWeek", new Poco { Name = x }));

ret = Redis.Custom("LRANGE", "DaysOfWeek", 1, -2);
var weekDays = ret.GetResults<Poco>();

Assert.That(weekDays.First().Name, Is.EqualTo("Monday"));

ret.PrintDump();
}
}
}

0 comments on commit 05ef270

Please sign in to comment.