|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
}
|