コード例 #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 Test2()
        {
            TestInit();

            //查询缓存测试
            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());

            //Update 会进行缓存清理
            Assert.True(p.Update() > 0);
            Assert.True(p1?.Count != p.Get()?.Count);
            Assert.True(count != p.Count());

            TestDelete();
        }