I am making DAO unit tests in my project and I have a problem using the ObjectSet
class. I have to create a new ObjectSet
but in order to do this, I must not connect to the DB. So I can not use the BusinessModelContainer
's CreateObjectSet()
method. Is there is a way to create the ObjectSet
without it?
The unit test code is like this:
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(...));
What are you testing? You should not need instance of real ObjectSet
in your unit test unless you are unit testing EF code. Use mock of IObjectSet
instead. There is no way to get instance of ObjectSet
without the context.
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>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With