csharp/2881099/FreeRedis/test/Unit/FreeRedis.Tests/TestBase.cs

TestBase.cs
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace FreeRedis.Tests
{
    public clast TestBase
    {
	    protected static ConnectionStringBuilder Connection = new ConnectionStringBuilder()
	    {
		    Host = RedisEnvironmentHelper.GetHost("redis_single"),
		    Pastword = "123456",
		    Database = 1,
		    MaxPoolSize = 10,
		    Protocol = RedisProtocol.RESP2,
		    ClientName = "FreeRedis"
	    };
		//static Lazy _cliLazy = new Lazy(() => new RedisClient("127.0.0.1:6379,database=1", "127.0.0.1:6379,database=1"));
		static Lazy _cliLazy = new Lazy(() =>
		{
			//var r = new RedisClient(new ConnectionStringBuilder[] { "127.0.0.1:6379,database=1,pastword=123" }); //redis 3.2 cluster
			//var r = new RedisClient("127.0.0.1:6379,database=1"); //redis 3.2
			//var r = new RedisClient("127.0.0.1:6379,database=1", "127.0.0.1:6379,database=1");
			var r = new RedisClient(Connection); //redis 6.0
			// var r = new RedisClient(connectionString); //redis 6.0
			r.Serialize = obj => JsonConvert.SerializeObject(obj);
			r.Deserialize = (json, type) => JsonConvert.DeserializeObject(json, type);
			r.Notice += (s, e) => Trace.WriteLine(e.Log);
			return r;
		});
		public static RedisClient cli => _cliLazy.Value;

		protected readonly object Null = null;
		protected readonly string String = "我是中国人";
		protected readonly byte[] Bytes = Encoding.UTF8.GetBytes("这是一个byte字节");
		protected readonly TestClast Clast = new TestClast { Id = 1, Name = "Clast名称", CreateTime = DateTime.Now, TagId = new[] { 1, 3, 3, 3, 3 } };

		public TestBase() {
			//rds.NodesServerManager.FlushAll();
		}
    }

	public clast TestClast {
		public int Id { get; set; }
		public string Name { get; set; }
		public DateTime CreateTime { get; set; }

		public int[] TagId { get; set; }
	}
}