I have a DbSet which I have mocked and exposed. I have filled some departments to the context. NOw when I access those Departments, I get null.
private Mock<DbSet<Department>> departmentSet;
private Mock<DemoEntities> context;
[TestInitializeAttribute()]
public void TestInit()
{
context = new Mock<DemoEntities>();
departmentSet = new Mock<DbSet<Department>>();
context.Setup(c => c.Departments).Returns(departmentSet.Object);
context.Object.Departments.Add(new Department() { Name = "HR", Id = 1 });
context.Object.Departments.Add(new Department() { Name = "Operations", Id = 2 });
context.Object.SaveChanges();
var list = context.Object.Departments; //returns null
}
Can anyone please let me know what I am doing wrong. As the rest of the test cases depend on accessing context.Object.Departments.