How to instantiate an ObjectSet?

I am doing DAO unit tests in my project and I have a problem using the class ObjectSet. I need to create a new one ObjectSet, but for this I should not connect to the database. Therefore, I cannot use the method BusinessModelContainer CreateObjectSet(). Is there any way to create ObjectSetwithout it?

The unit test code is as follows:

var mock = new Mock<IBusinessModelContainerWrapper>();  
ObjectSet<Student> expectedStudent = ???;  // how can I get an instance here?
StudentDao studentDao = new StudentDao(mock.Object);  

expectedStudent.Add(someObj);  
mock.Setup(c => c.Students).Returns(expectedStudent);  

Assert.AreEqual(someObj, studentDao.GetByQuery(...));  
+5
source share
2 answers

What are you testing? You do not need to have a real instance ObjectSetin your unit test if you are not testing the deviceโ€™s EF code. Use mock instead IObjectSet. Unable to get instance ObjectSetwithout context.

+10
DAL.Moles.MDALEntities.Constructor = (a) => { };
DALEntities db = new DALEntities(); //Object Context

System.Data.Objects.Moles.MObjectContext.AllInstances.CreateObjectSet<ObjectSetType>(
(a) => { return new System.Data.Objects.Moles.MObjectSet<ObjectSetType>(); }
);

ObjectSet<ObjectSetType> dbList = db.CreateObjectSet<ObjectSetType>();
+2

All Articles