当前位置: 首页>>代码示例>>C#>>正文


C# TestDbContext.AsCaching方法代码示例

本文整理汇总了C#中TestDbContext.AsCaching方法的典型用法代码示例。如果您正苦于以下问题:C# TestDbContext.AsCaching方法的具体用法?C# TestDbContext.AsCaching怎么用?C# TestDbContext.AsCaching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestDbContext的用法示例。


在下文中一共展示了TestDbContext.AsCaching方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromCacheFirstOrDefault_ItemIsNotAvailable

        public void FromCacheFirstOrDefault_ItemIsNotAvailable()
        {
            using (_dbContext.AsCaching())
            {
                Assert.That(_dbContext.Configuration.ProxyCreationEnabled, Is.False);
                Assert.That(_dbContext.Configuration.LazyLoadingEnabled, Is.False);

                var pinoGino = _dbContext.TestEntities1.Where(te => te.Name == Pino + Gino).FromCacheFirstOrDefault();
                Assert.That(pinoGino, Is.Null);

                using (var anotherContext = new TestDbContext(_dbConnection))
                using (anotherContext.AsCaching())
                {
                    pinoGino = _dbContext.TestEntities1.Where(te => te.Name == Pino + Gino).FromCacheFirstOrDefault();
                    Assert.That(pinoGino, Is.Null);
                }
            }
            Assert.That(_dbContext.Configuration.ProxyCreationEnabled, Is.True);
            Assert.That(_dbContext.Configuration.LazyLoadingEnabled, Is.True);
        }
开发者ID:pomma89,项目名称:KVLite,代码行数:20,代码来源:AbstractQueryCacheProviderTests.cs

示例2: FromCacheFirstOrDefault_ItemIsAvailable_TwoQueries_Async

        public async System.Threading.Tasks.Task FromCacheFirstOrDefault_ItemIsAvailable_TwoQueries_Async()
        {
            using (_dbContext.AsCaching())
            {
                Assert.That(_dbContext.Configuration.ProxyCreationEnabled, Is.False);
                Assert.That(_dbContext.Configuration.LazyLoadingEnabled, Is.False);

                var pino = await _dbContext.TestEntities1.Where(te => te.Name == Pino).FromCacheFirstOrDefaultAsync();
                Assert.That(pino, Is.Not.Null);
                Assert.That(pino.Name, Is.EqualTo(Pino));

                using (var anotherContext = new TestDbContext(_dbConnection))
                using (anotherContext.AsCaching())
                {
                    var gino = await anotherContext.TestEntities1.Where(te => te.Name == Gino).FromCacheFirstOrDefaultAsync();
                    Assert.That(gino, Is.Not.Null);
                    Assert.That(gino.Name, Is.EqualTo(Gino));
                }
            }
            Assert.That(_dbContext.Configuration.ProxyCreationEnabled, Is.True);
            Assert.That(_dbContext.Configuration.LazyLoadingEnabled, Is.True);
        }
开发者ID:pomma89,项目名称:KVLite,代码行数:22,代码来源:AbstractQueryCacheProviderTests.cs

示例3: FromCache_ItemsAreAvaialable_DifferentQueries_WithTags

        public void FromCache_ItemsAreAvaialable_DifferentQueries_WithTags()
        {
            using (_dbContext.AsCaching())
            {
                var inis = _dbContext.TestEntities1.FromCache(tags: new[] { Pino, Gino, Nino });
                Assert.That(inis, Is.Not.Null);
                Assert.That(inis.Count(), Is.EqualTo(3));
                Assert.That(inis.Count(i => i.Name == Pino), Is.EqualTo(1));
                Assert.That(inis.Count(i => i.Name == Gino), Is.EqualTo(1));
                Assert.That(inis.Count(i => i.Name == Nino), Is.EqualTo(1));

                Assert.That(Cache.GetItems<object>().Count, Is.EqualTo(4));

                using (var anotherContext = new TestDbContext(_dbConnection))
                using (anotherContext.AsCaching())
                {
                    inis = _dbContext.TestEntities1.Where(te => te.Name == Pino || te.Name == Nino).FromCache(tags: new[] { Pino, Nino });
                    Assert.That(inis, Is.Not.Null);
                    Assert.That(inis.Count(), Is.EqualTo(2));
                    Assert.That(inis.Count(i => i.Name == Pino), Is.EqualTo(1));
                    Assert.That(inis.Count(i => i.Name == Gino), Is.EqualTo(0));
                    Assert.That(inis.Count(i => i.Name == Nino), Is.EqualTo(1));

                    if (Cache is MemoryCache)
                    {
                        // FIXME: MemoryCache is triggering one more delete than necessary. 
                        //        Of course, this is a broken behaviour, but there is no easy way to fix it right now.
                        Assert.That(Cache.GetItems<object>().Count, Is.EqualTo(4));
                        Assert.Ignore("MemoryCache has a partially buggy behavior...");
                    }
                    else
                    {
                        // This is the right behavior.
                        Assert.That(Cache.GetItems<object>().Count, Is.EqualTo(5));
                    }
                }
            }
        }
开发者ID:pomma89,项目名称:KVLite,代码行数:38,代码来源:AbstractQueryCacheProviderTests.cs

示例4: FromCache_ItemsAreAvaialable_Async

        public async System.Threading.Tasks.Task FromCache_ItemsAreAvaialable_Async()
        {
            using (_dbContext.AsCaching())
            {
                Assert.That(_dbContext.Configuration.ProxyCreationEnabled, Is.False);
                Assert.That(_dbContext.Configuration.LazyLoadingEnabled, Is.False);

                var inis = await _dbContext.TestEntities1.FromCacheAsync();
                Assert.That(inis, Is.Not.Null);
                Assert.That(inis.Count(), Is.EqualTo(3));
                Assert.That(inis.Count(i => i.Name == Pino), Is.EqualTo(1));
                Assert.That(inis.Count(i => i.Name == Gino), Is.EqualTo(1));
                Assert.That(inis.Count(i => i.Name == Nino), Is.EqualTo(1));

                using (var anotherContext = new TestDbContext(_dbConnection))
                using (anotherContext.AsCaching())
                {
                    inis = await _dbContext.TestEntities1.FromCacheAsync();
                    Assert.That(inis, Is.Not.Null);
                    Assert.That(inis.Count(), Is.EqualTo(3));
                    Assert.That(inis.Count(i => i.Name == Pino), Is.EqualTo(1));
                    Assert.That(inis.Count(i => i.Name == Gino), Is.EqualTo(1));
                    Assert.That(inis.Count(i => i.Name == Nino), Is.EqualTo(1));
                }
            }
            Assert.That(_dbContext.Configuration.ProxyCreationEnabled, Is.True);
            Assert.That(_dbContext.Configuration.LazyLoadingEnabled, Is.True);
        }
开发者ID:pomma89,项目名称:KVLite,代码行数:28,代码来源:AbstractQueryCacheProviderTests.cs

示例5: FromCache_ItemsAreAvaialable_DifferentQueries

        public void FromCache_ItemsAreAvaialable_DifferentQueries()
        {
            using (_dbContext.AsCaching())
            {
                var inis = _dbContext.TestEntities1.FromCache();
                Assert.That(inis, Is.Not.Null);
                Assert.That(inis.Count(), Is.EqualTo(3));
                Assert.That(inis.Count(i => i.Name == Pino), Is.EqualTo(1));
                Assert.That(inis.Count(i => i.Name == Gino), Is.EqualTo(1));
                Assert.That(inis.Count(i => i.Name == Nino), Is.EqualTo(1));

                Assert.That(Cache.GetItems<object>().Count, Is.EqualTo(1));

                using (var anotherContext = new TestDbContext(_dbConnection))
                using (anotherContext.AsCaching())
                {
                    inis = _dbContext.TestEntities1.Where(te => te.Name == Pino || te.Name == Nino).FromCache();
                    Assert.That(inis, Is.Not.Null);
                    Assert.That(inis.Count(), Is.EqualTo(2));
                    Assert.That(inis.Count(i => i.Name == Pino), Is.EqualTo(1));
                    Assert.That(inis.Count(i => i.Name == Gino), Is.EqualTo(0));
                    Assert.That(inis.Count(i => i.Name == Nino), Is.EqualTo(1));

                    Assert.That(Cache.GetItems<object>().Count, Is.EqualTo(2));
                }
            }
        }
开发者ID:pomma89,项目名称:KVLite,代码行数:27,代码来源:AbstractQueryCacheProviderTests.cs


注:本文中的TestDbContext.AsCaching方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。