本文整理汇总了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);
}
示例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);
}
示例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));
}
}
}
}
示例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);
}
示例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));
}
}
}