4

I've shimmed my data context. Now I need to shim a table get(). I'm running into issues with ObjectSet, since I don't know how to shim it.

DataModel.Fakes.ShimMyEntities.Constructor = (inst) => {};
DataModel.Fakes.ShimMyEntities.AllInstances.Table1Get = (i)
  => ?

//In codebase

using(MyEntities ctx = new MyEntities())
{
  ctx.Table1.ToList().ForEach(i => otherList.Add(i));
}

What should go where the question mark above is? I've tried variations of the following in place of the question mark but nothing so far works:

=> { return new ObjectSet<Table1>(){ new ObjectContext("").CreateObjectSet<Table1>();} ; }

and

=> { return System.Data.Objects.Fakes.ShimObjectContext.AllInstances.CreateObjectSetOf1String<Table1>(inst, var1)   ???
4thSpace
  • 43,672
  • 97
  • 296
  • 475
  • I haven't used MS Fakes, but I have used Moq and DbSet/DbContext as outlined at http://msdn.microsoft.com/en-us/library/dn314429.aspx. Maybe that article will help you. – Phil Apr 28 '14 at 07:33
  • This issue is specific to MS Fakes. – 4thSpace Apr 28 '14 at 15:39

1 Answers1

2

The following is how I do it:

var shimTable1ObjectSet = new System.Data.Objects.Fakes.ShimObjectSet<Table1>();
shimTable1ObjectSet.Bind((new List<Table1>()).AsQueryable());
DataModel.Fakes.ShimMyEntities.Constructor = (inst) => {};
DataModel.Fakes.ShimMyEntities.AllInstances.Table1Get = () => shimTable1ObjectSet.Instance;

With that you will be able to do ToList(), Count(), Where(), etc on that ctx.Table1.

scottheckel
  • 9,106
  • 1
  • 35
  • 47