public void QueryCacheExpired(int count)
 {
     using (var db = new LocalQueryCache())
     {
         for (int i = 0; i < count; i++)
         {
             var re = db.Queryable <OperateTestModel>().Where(t => t.StringKey.Contains("test")).ToOne();
             Assert.NotNull(re);
         }
     }
 }
        public void QueryBugRepaire2()
        {
            int metaObjectId = 1;

            using (var db = new LocalQueryCache())
            {
                for (int i = 0; i < 3; i++)
                {
                    var re = db.Queryable <OperateTestModel>().Where(t => t.IntNullKey == 1 && t.IntKey == metaObjectId).ToList();
                    Assert.NotNull(re);
                }
            }
        }
Exemplo n.º 3
0
        public void QueryWhereWithUnSameCondition()
        {
            using (var db = new LocalQueryCache())
            {
                db.Queryable <OperationTest>().Where(t => t.Id == 1).FirstOrDefault();

                Assert.False(db.IsFromCache);

                db.Queryable <OperationTest>().Where(t => t.Id == 2).FirstOrDefault();

                Assert.False(db.IsFromCache);
            }
        }
Exemplo n.º 4
0
        public void QueryAll()
        {
            using (var db = new LocalQueryCache())
            {
                db.Queryable <OperationTest>().ToList();

                Assert.False(db.IsFromCache);

                db.Queryable <OperationTest>().ToList();

                Assert.True(db.IsFromCache);
            }
        }
        public void QueryWhereWithUnSameCondition2(int count)
        {
            using (var db = new LocalQueryCache())
            {
                db.DbCacheManager.FlushCurrentCollectionCache(db.GetTableName <OperateTestModel>());

                for (int i = 1; i <= count; i++)
                {
                    var re = db.Queryable <OperateTestModel>().Where(t => t.Id == i).ToOne();

                    Assert.True(!db.IsFromCache);
                    Assert.NotNull(re);
                }
            }
        }
Exemplo n.º 6
0
        public void QueryCount()
        {
            using (var db = new LocalQueryCache())
            {
                db.Queryable <OperationTest>().Where(t => t.StringKey.Contains("test")).Count();

                Assert.False(db.IsFromCache);

                var result = db.Queryable <OperationTest>().Where(t => t.StringKey.Contains("test")).Count();

                Assert.True(db.IsFromCache);

                Assert.Equal(0, result);
            }
        }
Exemplo n.º 7
0
        public void QueryCacheExpired()
        {
            using (var db = new LocalQueryCache())
            {
                db.Queryable <OperationTest>().Where(t => t.Id == 1).FirstOrDefault();

                db.Queryable <OperationTest>().Where(t => t.Id == 1).FirstOrDefault();

                Assert.True(db.IsFromCache);

                Thread.Sleep(_CacheSecends * 1000);

                db.Queryable <OperationTest>().Where(t => t.Id == 1).FirstOrDefault();

                Assert.False(db.IsFromCache);
            }
        }
        public void QueryOne(int count)
        {
            using (var db = new LocalQueryCache())
            {
                for (int i = 0; i < count; i++)
                {
                    var re = db.Queryable <OperateTestModel>().Where(t => t.StringKey.Contains("test")).ToOne();

                    if (i == 0)
                    {
                        Assert.True(!db.IsFromCache);
                    }
                    else
                    {
                        Assert.True(db.IsFromCache);
                    }

                    Assert.NotNull(re);
                }
            }
        }
        public void QueryAll(int count)
        {
            using (var db = new LocalQueryCache())
            {
                for (int i = 0; i < count; i++)
                {
                    var re = db.Queryable <OperateTestModel>().ToList();

                    if (i == 0)
                    {
                        Assert.True(!db.IsFromCache);
                    }
                    else
                    {
                        Assert.True(db.IsFromCache);
                    }

                    Assert.Equal(1000, re.Count);
                }
            }
        }
Exemplo n.º 10
0
        public void Add()
        {
            using (var db = new LocalQueryCache())
            {
                //先查询肯定是没有的
                db.Queryable <OperationTest>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.False(db.IsFromCache);

                //第二次在缓存中可以查到
                db.Queryable <OperationTest>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.True(db.IsFromCache);

                //Add操作会清空一级缓存
                db.Add(new OperationTest {
                });

                //这时候查询应该从缓存获取不到
                db.Queryable <OperationTest>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.False(db.IsFromCache);
            }
        }
        public void QueryAdd()
        {
            using (var db = new LocalQueryCache())
            {
                //1.先查询肯定是没有的
                var re0 = db.Queryable <OperateTestModel>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.Null(re0);

                db.Add(new OperateTestModel
                {
                    IntKey    = 123,
                    StringKey = "CacheAddTest123"
                });

                //2.这时候查询应该有一条,这次查询才加入缓存
                var re = db.Queryable <OperateTestModel>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.Single(re);

                //3.重复查询,这次是从缓存查的,还是一条
                var re2 = db.Queryable <OperateTestModel>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.Single(re2);

                //再次新增,清楚一级缓存
                db.Add(new OperateTestModel
                {
                    IntKey    = 123,
                    StringKey = "CacheAddTest123"
                });

                //4.这次查应该从数据库查询,加入缓存,2条
                var re4 = db.Queryable <OperateTestModel>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.Equal(2, re4.Count);

                db.Delete <OperateTestModel>(t => t.StringKey.StartsWith("CacheAddTest"));

                //4.删除完毕以后,查询是没有的
                var re3 = db.Queryable <OperateTestModel>().Where(t => t.StringKey.StartsWith("CacheAddTest")).ToList();
                Assert.Null(re3);
            }
        }
        public void QueryWhereWithUnSameCondition(int count)
        {
            using (var db = new LocalQueryCache())
            {
                for (int i = 0; i < count; i++)
                {
                    var re  = db.Queryable <OperateTestModel>().Where(t => t.Id == 1).ToOne();
                    var re1 = db.Queryable <OperateTestModel>().Where(t => t.Id == 2).ToOne();

                    if (i == 0)
                    {
                        Assert.True(!db.IsFromCache);
                    }
                    else
                    {
                        Assert.True(db.IsFromCache);
                    }

                    Assert.NotEqual(re.StringKey, re1.StringKey);
                }
            }
        }