Mocking Entity Framwork using Moq not returning DbSet<T>
<p>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.</p>

<pre><code>    private Mock&lt;DbSet&lt;Department&gt;&gt; departmentSet;
    private Mock&lt;DemoEntities&gt; context;

    [TestInitializeAttribute()]
    public void TestInit()
    {
        context = new Mock&lt;DemoEntities&gt;();
        departmentSet = new Mock&lt;DbSet&lt;Department&gt;&gt;();
        context.Setup(c =&gt; 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
     }
</code></pre>

<p>Can anyone please let me know what I am doing wrong. As the rest of the test cases depend on accessing context.Object.Departments.</p>