Microsoft伪造品:无法加载相关实体

时间:2019-01-30 22:00:57

标签: c# .net unit-testing microsoft-fakes

在设置简单的单元测试时需要一些帮助。一切看起来不错,但是当我的查询中包含或分组时,我的查询失败了。

Table1是主表 Table2与带有外键的Table1相关

我要测试的方法

public void GetSomeData(){

//There are other conditions that are part of query   
 var response = dbCtx.Table1.Include(x => x.Table2).Where(y => y.fiel1 == true);
 }

TestMethod

public void TestingSomething(){

  List<Table1> obj1= new List<Table1>();
  List<Table2> obj2 = new List<Table2>();

  using(ShimContext.Create()){
  ShimDbSet<Table1> shimDbSetTable1 = new ShimDbnSet<Table1>();
  ShimDbSet<Table2> shimDbSetTable2 = new ShimDbnSet<Table2>();
  shimDbSetTable1.Bind(obj1.AsQueryable());
  shimDbSetTable2.Bind(obj2.AsQueryable());

  ShimMyEntity.AllInstances.Table1Get = (a) => {return shimDbSetTable1.instance;}

  ShimMyEntity.AllInstances.Table2Get = (a) => {return shimDbSetTable2.instance;}

 //Call GetSomeData
 GetSomeData();

//Bunch of Asserts
}

运行GetSomeData中的查询时,它返回错误值不能为null。参数名称来源。

我猜测它与相关的表无法做到时,得到表2处理

有人可以帮我看看如何设置测试,以便也可以加载相关实体吗?

0 个答案:

没有答案