RedisSortedSetStudyTest

master
ruyu 7 years ago
parent 01f6b5b025
commit 040c7f96c4

@ -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<Student> students;
/// <summary>
/// 构造
/// </summary>
public RedisSortSetStudyTest()
{
redisDatabase = RedisHelper.GetRedisDatabase();
sortSetStudy = new RedisSortSetStudy();
students = new List<Student>()
{
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
},
};
}
/// <summary>
/// 清理
/// </summary>
public void Dispose()
{
redisDatabase.KeyDelete("student:age:rank");
}
}
}

@ -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
{
/// <summary>
/// Redis 集合学习 测试
/// </summary>
[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";
/// <summary>
/// 构造
/// </summary>
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
}
}

@ -80,10 +80,10 @@
<Compile Include="RedisHashStudyTest.cs" />
<Compile Include="RedisLockStudyTest.cs" />
<Compile Include="RedisListStudyTest.cs" />
<Compile Include="RedisSortedSetStudyTest.cs" />
<Compile Include="RedisSetStudyTest.cs" />
<Compile Include="RedisStringStudyTest.cs" />
<Compile Include="RedisStudyTest.cs" />
<Compile Include="RedisSortSetStudyTest.cs" />
<Compile Include="RedisHelperTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RedisServerStudyTest.cs" />

@ -12,7 +12,7 @@ namespace RedisStuy
/// <summary>
/// 有序集合操作
/// </summary>
public class RedisSortSetStudy
public class RedisSortedSetStudy
{
#region 初始化
private IDatabase redisDatabase = RedisHelper.GetRedisDatabase();

@ -52,7 +52,7 @@
<Compile Include="RedisLockStudy.cs" />
<Compile Include="RedisScanStudy.cs" />
<Compile Include="RedisSetStudy.cs" />
<Compile Include="RedisSortSetStudy.cs" />
<Compile Include="RedisSortedSetStudy.cs" />
<Compile Include="RedisTransactionStudy.cs" />
<Compile Include="RedisStringStudy.cs" />
<Compile Include="RedisServerStudy.cs" />

Loading…
Cancel
Save