From fc7c0f385f0a8f0334801fddc0bc32592e99fdb9 Mon Sep 17 00:00:00 2001 From: ruyu Date: Sat, 30 Jun 2018 20:29:16 +0800 Subject: [PATCH] RedisListStudyTest --- RedisStudyTest/RedisListStudyTest.cs | 87 +++++++++++++++++++++++++++- RedisStuy/RedisListStudy.cs | 2 +- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/RedisStudyTest/RedisListStudyTest.cs b/RedisStudyTest/RedisListStudyTest.cs index 357b5db..75fc936 100644 --- a/RedisStudyTest/RedisListStudyTest.cs +++ b/RedisStudyTest/RedisListStudyTest.cs @@ -78,13 +78,96 @@ namespace RedisStudyTest } #endregion - #region + #region ListInsertBefore + /// + /// Key不存在时,不执行操作,返回0 + /// [Fact] - public void Test() + public void ListInsertBeforeNotKeyTest() { var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "first", "firstBefore"); Assert.Equal(0, listLenth); } + + /// + /// 未找到指定参照值时,返回 -1 + /// + [Fact] + public void ListInsertBeforeNotPivotTest() + { + redisListStudy.ListLeftPush(defaultRedisKey, "second"); + + var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "first", "firstBefore"); + Assert.Equal(-1, listLenth); + } + + [Fact] + public void ListInsertBeforeTest() + { + redisListStudy.ListLeftPush(defaultRedisKey, "third"); + + var listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "third", "second"); + Assert.Equal(2, listLenth); + + listLenth = redisListStudy.ListInsertBefore(defaultRedisKey, "second", "first"); + Assert.Equal(3, listLenth); + } + #endregion + + #region ListInsertAfter + /// + /// Key不存在时,不执行操作,返回0 + /// + [Fact] + public void ListInsertAfterNotKeyTest() + { + var listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "first", "firstAfter"); + Assert.Equal(0, listLenth); + } + + /// + /// 未找到指定参照值时,返回 -1 + /// + [Fact] + public void ListInsertAfterNotPivotTest() + { + redisListStudy.ListLeftPush(defaultRedisKey, "second"); + + var listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "first", "firstAfter"); + Assert.Equal(-1, listLenth); + } + + [Fact] + public void ListInsertAfterTest() + { + redisListStudy.ListLeftPush(defaultRedisKey, "first"); + + var listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "first", "second"); + Assert.Equal(2, listLenth); + + listLenth = redisListStudy.ListInsertAfter(defaultRedisKey, "second", "third"); + Assert.Equal(3, listLenth); + } + #endregion + + #region ListSetByIndex + [Fact] + public void ListGetByIndexNotKeyTest() + { + Assert.Throws(() => redisListStudy.ListSetByIndex(defaultRedisKey, 0, "first")); + } + + [Fact] + public void ListSetByIndexTest() + { + redisListStudy.ListLeftPush(defaultRedisKey, "first"); + + redisListStudy.ListSetByIndex(defaultRedisKey,0,"firstSetByIndex"); + + var first = redisListStudy.ListLeftPop(defaultRedisKey); + + Assert.Equal("firstSetByIndex", first); + } #endregion #region 清理 diff --git a/RedisStuy/RedisListStudy.cs b/RedisStuy/RedisListStudy.cs index 8ecfebb..1002d14 100644 --- a/RedisStuy/RedisListStudy.cs +++ b/RedisStuy/RedisListStudy.cs @@ -97,7 +97,7 @@ namespace RedisStuy /// /// /// 插入后,列表长度 - /// 未找到指定key值时,返回 -1 + /// 未找到指定参照值时,返回 -1 /// public long ListInsertBefore(RedisKey key, RedisValue pivot, RedisValue value, CommandFlags flags = CommandFlags.None) {