我尝试像这样测试我导入的函数:
[TestMethod]
public void TestCustomerById()
{
using (var ctx = new AWLT.AWLT())
{
var customer = ctx.GetCustomerById(1);
// Assert.AreNotEqual(0, customer.Count());
Assert.AreNotEqual(0,
((IObjectContextAdapter)ctx).ObjectContext
.ObjectStateManager
.GetObjectStateEntries(System.Data.Entity.EntityState.Unchanged).Count());
}
}
当我调试测试并尝试快速观看customer
时,我得到:
枚举没有产生结果
虽然当我运行程序时,它会返回一个客户!!
答案 0 :(得分:0)
你应该调用.ToList()强制枚举。
[TestMethod]
public void TestCustomerById()
{
using (var ctx = new AWLT.AWLT())
{
var customer = ctx.GetCustomerById(1).ToList();
// Assert.AreNotEqual(0, customer.Count());
Assert.AreNotEqual(0,
((IObjectContextAdapter)ctx).ObjectContext
.ObjectStateManager
.GetObjectStateEntries(System.Data.Entity.EntityState.Unchanged).Count());
}
}