public void Test11() { TestInit(); //查询缓存测试 var a1 = a.Get(); Assert.True(a1?.Count > 0); //再添加 Assert.True(a.Add() > 0); //因为配置了查询缓存,而且Add并没有进行清理缓存 Assert.True(a1?.Count == a.Get()?.Count); Thread.Sleep(3000); //每次获取之后都会更新缓存期限 Assert.True(a1?.Count == a.Get()?.Count); Thread.Sleep(3000); Assert.True(a1?.Count == a.Get()?.Count); //5秒后过期 Thread.Sleep(5000); Assert.True(a1?.Count != a.Get()?.Count); TestDelete(); }
public void TestThread() { DbContext db = new MSSqlDBContext(); var p = new LuaPersonCacheBLL(db); var a = new LuaAddressCacheBLL(db); TestInit(p, a); List <Task> ts = new List <Task>(); int forcount = 100; for (int i = 0; i < forcount; i++) { ts.Add(Task.Run(() => { DbContext db1 = new MSSqlDBContext(); var pt = new LuaPersonCacheBLL(db1); var at = new LuaAddressCacheBLL(db1); pt.Add(); pt.Count(); pt.Update(); pt.Delete(); at.Add(); at.Count(); at.Update(); at.Delete(); })); } Task.WaitAll(ts.ToArray()); TestDelete(p, a); }
void TestInit(LuaPersonCacheBLL p = null, LuaAddressCacheBLL a = null) { p = p ?? this.p; a = a ?? this.a; //先清理旧数据 和 添加新数据 p.Delete(); a.Delete(); Assert.True(p.Add() > 0); Assert.True(a.Add() > 0); }