Redis/XUnitTest/SetTest.cs

64 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewLife.Caching;
using NewLife.Log;
using Xunit;
namespace XUnitTest;
[Collection("Basic")]
public class SetTest
{
protected readonly FullRedis _redis;
public SetTest()
{
var config = BasicTest.GetConfig();
_redis = new FullRedis();
_redis.Init(config);
_redis.Log = XTrace.Log;
#if DEBUG
_redis.ClientLog = XTrace.Log;
#endif
}
[Fact]
public void Search()
{
var rkey = "set_Search";
// 删除已有
_redis.Remove(rkey);
var set = _redis.GetSet<String>(rkey);
var set2 = set as RedisSet<String>;
// 插入数据
set.Add("stone1");
set.Add("stone2");
set.Add("stone3");
set.Add("stone4");
Assert.Equal(4, set.Count);
Assert.True(set.Contains("stone4"));
// 搜索。这里为了Assert每一项要排序因为输出顺序可能不确定
var dic = set2.Search("*one?", 4).OrderBy(e => e).ToList();
Assert.Equal(4, dic.Count);
Assert.Equal("stone1", dic[0]);
Assert.Equal("stone2", dic[1]);
Assert.Equal("stone3", dic[2]);
}
}
public class SetTest2 : SetTest
{
public SetTest2() : base()
{
_redis.Prefix = "NewLife:";
}
}