예제 #1
0
        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);
        }
예제 #2
0
        public void Test21()
        {
            DbContext db = new MSSqlDBContext();
            var       p  = new LuaPersonCacheBLL(db);
            var       a  = new LuaAddressCacheBLL(db);

            TestInit(p, a);

            //查询缓存测试
            var p1    = p.Get();
            var count = p.Count();

            Assert.True(p1?.Count > 0);
            Assert.True(count > 0);
            //再添加
            Assert.True(p.Add() > 0);
            //因为配置了查询缓存,而且Add并没有进行清理缓存
            Assert.True(p1?.Count == p.Get()?.Count);
            Assert.True(count == p.Count());

            //AddEx 会进行缓存清理(AddEx是使用Scalar进行新增操作的,用于获取自增id)
            Assert.True(p.AddEx() > 0);
            Assert.True(p1?.Count != p.Get()?.Count);
            Assert.True(count != p.Count());

            TestDelete();
        }
예제 #3
0
 void TestDelete(LuaPersonCacheBLL p = null, LuaAddressCacheBLL a = null)
 {
     p = p ?? this.p;
     a = a ?? this.a;
     //先清理旧数据 和 添加新数据
     p.Delete();
     a.Delete();
 }
예제 #4
0
 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);
 }