From 040c7f96c41f378ab6db085d98f8cca24a936e98 Mon Sep 17 00:00:00 2001 From: ruyu Date: Sun, 1 Jul 2018 19:11:12 +0800 Subject: [PATCH] RedisSortedSetStudyTest --- RedisStudyTest/RedisSortSetStudyTest.cs | 74 ----------------- RedisStudyTest/RedisSortedSetStudyTest.cs | 81 +++++++++++++++++++ RedisStudyTest/RedisStudyTest.csproj | 2 +- ...SortSetStudy.cs => RedisSortedSetStudy.cs} | 2 +- RedisStuy/RedisStuy.csproj | 2 +- 5 files changed, 84 insertions(+), 77 deletions(-) delete mode 100644 RedisStudyTest/RedisSortSetStudyTest.cs create mode 100644 RedisStudyTest/RedisSortedSetStudyTest.cs rename RedisStuy/{RedisSortSetStudy.cs => RedisSortedSetStudy.cs} (99%) diff --git a/RedisStudyTest/RedisSortSetStudyTest.cs b/RedisStudyTest/RedisSortSetStudyTest.cs deleted file mode 100644 index ef23cbf..0000000 --- a/RedisStudyTest/RedisSortSetStudyTest.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Xunit; - -using RedisStudyModel; - -using StackExchange; -using StackExchange.Redis; - -using RedisStuy; - -namespace RedisStudyTest -{ - [Trait("RedisSortSet", "All")] - public class RedisSortSetStudyTest : IDisposable - { - private IDatabase redisDatabase = null; - private RedisSortSetStudy sortSetStudy = null; - private List students; - - /// - /// 构造 - /// - public RedisSortSetStudyTest() - { - redisDatabase = RedisHelper.GetRedisDatabase(); - sortSetStudy = new RedisSortSetStudy(); - students = new List() - { - new Student() - { - Id = 1001, - Name = "王高峰", - Age = 11 - }, - new Student() - { - Id = 1002, - Name = "王高峰2", - Age = 22 - }, - new Student() - { - Id = 1003, - Name = "王高峰3", - Age = 33 - }, - new Student() - { - Id = 1004, - Name = "王高峰4", - Age = 44 - }, - new Student() - { - Id = 1005, - Name = "王高峰5", - Age = 55 - }, - }; - } - - /// - /// 清理 - /// - public void Dispose() - { - redisDatabase.KeyDelete("student:age:rank"); - } - } -} diff --git a/RedisStudyTest/RedisSortedSetStudyTest.cs b/RedisStudyTest/RedisSortedSetStudyTest.cs new file mode 100644 index 0000000..24a4b0f --- /dev/null +++ b/RedisStudyTest/RedisSortedSetStudyTest.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using StackExchange.Redis; + +using Xunit; +using Xunit.Extensions; +using Xunit.Serialization; +using Xunit.Abstractions; +using Xunit.Sdk; + +using RedisStuy; + +namespace RedisStudyTest +{ + /// + /// Redis 集合学习 测试 + /// + [Trait("RedisSortedSet", "All")] + public class RedisSortedSetStudyTest : IDisposable + { + #region 初始化 + private readonly ITestOutputHelper testOutput; + private IDatabase redisDatabase = null; + private RedisSortedSetStudy redisSortedSetStudy = null; + private TimeSpan defaultExpiry = TimeSpan.FromSeconds(20); + private string defaultRedisKey = "RedisStudy:SortedSet:xUnitTest"; + + /// + /// 构造 + /// + public RedisSortedSetStudyTest(ITestOutputHelper output) + { + this.testOutput = output; + redisDatabase = RedisHelper.GetRedisDatabase(); + redisSortedSetStudy = new RedisSortedSetStudy(); + } + #endregion + + #region SetAdd + + [Fact] + public void SortedAdd_NotKey_Test() + { + var addNumber = redisSortedSetStudy.SortedSetAdd(defaultRedisKey, new SortedSetEntry[] { }, CommandFlags.None); + Assert.Equal(0, addNumber); + + var exits = redisDatabase.KeyExists(defaultRedisKey); + Assert.False(exits); + + var result = redisSortedSetStudy.SortedSetAdd(defaultRedisKey,"first",1,CommandFlags.None); + Assert.True(result); + + var number = redisSortedSetStudy.SortedSetLength(defaultRedisKey); + Assert.Equal(1, number); + } + + [Fact] + public void SetAdd_SortedSetEntrys_Empty_Test() + { + SortedSetEntry sortedSetEntry = new SortedSetEntry("first", 1); + + var addNumber = redisSortedSetStudy.SortedSetAdd(defaultRedisKey, new SortedSetEntry[] { }, CommandFlags.None); + Assert.Equal(0, addNumber); + + var result = redisSortedSetStudy.SortedSetAdd(defaultRedisKey, "first",1,CommandFlags.None); + Assert.True(result); + } + #endregion + + #region 清理 + public void Dispose() + { + redisDatabase.KeyDelete(defaultRedisKey); + } + #endregion + } +} diff --git a/RedisStudyTest/RedisStudyTest.csproj b/RedisStudyTest/RedisStudyTest.csproj index a201176..6b31c11 100644 --- a/RedisStudyTest/RedisStudyTest.csproj +++ b/RedisStudyTest/RedisStudyTest.csproj @@ -80,10 +80,10 @@ + - diff --git a/RedisStuy/RedisSortSetStudy.cs b/RedisStuy/RedisSortedSetStudy.cs similarity index 99% rename from RedisStuy/RedisSortSetStudy.cs rename to RedisStuy/RedisSortedSetStudy.cs index d2ada9f..4150f5d 100644 --- a/RedisStuy/RedisSortSetStudy.cs +++ b/RedisStuy/RedisSortedSetStudy.cs @@ -12,7 +12,7 @@ namespace RedisStuy /// /// 有序集合操作 /// - public class RedisSortSetStudy + public class RedisSortedSetStudy { #region 初始化 private IDatabase redisDatabase = RedisHelper.GetRedisDatabase(); diff --git a/RedisStuy/RedisStuy.csproj b/RedisStuy/RedisStuy.csproj index 3ceb585..2fb6e38 100644 --- a/RedisStuy/RedisStuy.csproj +++ b/RedisStuy/RedisStuy.csproj @@ -52,7 +52,7 @@ - +