本文整理汇总了C#中TestContext.GetObjectContext方法的典型用法代码示例。如果您正苦于以下问题:C# TestContext.GetObjectContext方法的具体用法?C# TestContext.GetObjectContext怎么用?C# TestContext.GetObjectContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestContext
的用法示例。
在下文中一共展示了TestContext.GetObjectContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Queryable_AsTracking
public void Queryable_AsTracking()
{
TestContext.DeleteAll(x => x.Entity_Basics);
TestContext.Insert(x => x.Entity_Basics, 10);
using (var ctx = new TestContext())
{
// BEFORE
var futureList1 = ctx.Entity_Basics.Where(x => x.ColumnInt < 5).Future();
var futureList2 = ctx.Entity_Basics.Where(x => x.ColumnInt >= 5).Future();
// TEST: The batch contains 2 queries
Assert.AreEqual(2, QueryFutureManager.AddOrGetBatch(ctx.GetObjectContext()).Queries.Count);
var list = futureList1.ToList();
// AFTER
// TEST: The batch contains 0 queries
Assert.AreEqual(0, QueryFutureManager.AddOrGetBatch(ctx.GetObjectContext()).Queries.Count);
// TEST: The futureList1 has a value and the list contains 5 items
Assert.IsTrue(futureList1.HasValue);
Assert.AreEqual(5, futureList1.ToList().Count);
Assert.AreEqual(5, list.Count);
// TEST: The futureList2 has a value and the list contains 5 items
Assert.IsTrue(futureList2.HasValue);
Assert.AreEqual(5, futureList2.ToList().Count);
// TEST: All entries has been loaded in the change tracker
Assert.AreEqual(10, ctx.ChangeTracker.Entries().Count());
}
}
示例2: Queryable_AsNoTracking
public void Queryable_AsNoTracking()
{
TestContext.DeleteAll(x => x.Entity_Basics);
TestContext.Insert(x => x.Entity_Basics, 10);
using (var ctx = new TestContext())
{
// BEFORE
var futureValue1 = ctx.Entity_Basics.Where(x => x.ColumnInt < 5).OrderBy(x => x.ColumnInt).AsNoTracking().FutureValue();
var futureValue2 = ctx.Entity_Basics.Where(x => x.ColumnInt >= 5).OrderBy(x => x.ColumnInt).AsNoTracking().FutureValue();
// TEST: The batch contains 2 queries
Assert.AreEqual(2, QueryFutureManager.AddOrGetBatch(ctx.GetObjectContext()).Queries.Count);
var value = futureValue1.Value;
// AFTER
// TEST: The batch contains 0 queries
Assert.AreEqual(0, QueryFutureManager.AddOrGetBatch(ctx.GetObjectContext()).Queries.Count);
// TEST: The futureList1 has a value and the first item is returned
Assert.IsTrue(futureValue1.HasValue);
Assert.AreEqual(0, value.ColumnInt);
// TEST: The futureList2 has a value and the first item is returned
Assert.IsTrue(futureValue2.HasValue);
Assert.AreEqual(5, futureValue2.Value.ColumnInt);
// TEST: No entries has been loaded in the change tracker
Assert.AreEqual(0, ctx.ChangeTracker.Entries().Count());
}
}
示例3: DelayedQuery_AsTracking
public void DelayedQuery_AsTracking()
{
TestContext.DeleteAll(x => x.Entity_Basics);
TestContext.Insert(x => x.Entity_Basics, 10);
using (var ctx = new TestContext())
{
// BEFORE
var futureValue1 = ctx.Entity_Basics.Where(x => x.ColumnInt < 5).DeferredCount().FutureValue();
var futureValue2 = ctx.Entity_Basics.Where(x => x.ColumnInt >= 5).DeferredCount().FutureValue();
// TEST: The batch contains 2 queries
Assert.AreEqual(2, QueryFutureManager.AddOrGetBatch(ctx.GetObjectContext()).Queries.Count);
var value = futureValue1.Value;
// AFTER
// TEST: The batch contains 0 queries
Assert.AreEqual(0, QueryFutureManager.AddOrGetBatch(ctx.GetObjectContext()).Queries.Count);
// TEST: The futureValue1 has a value and the count equal 5
Assert.IsTrue(futureValue1.HasValue);
Assert.AreEqual(5, value);
// TEST: The futureValue2 has a value and the count equal 5
Assert.IsTrue(futureValue2.HasValue);
Assert.AreEqual(5, futureValue2.Value);
// TEST: No entries has been loaded in the change tracker (A value is returned, not an entity)
Assert.AreEqual(0, ctx.ChangeTracker.Entries().Count());
}
}