I read this post about mocking Entity Framework(EF).
Shouldn’t we abstract the entities’ types as well? In order to preserve decoupling between the Data Access Layer (DAL) and the Business Layer (BL)?
In the above post, he used EF concrete generated entities types:
[TestMethod]
public void GetCustomer()
{
ContextContainerMock container = new ContextContainerMock();
IMyEntities en = container.Current;
**Customer c = new Customer { ID = 1, FirstName = "John", LastName = "Doe" };**
en.Customers.AddObject(c);
CustomerService service = new CustomerService(container);
var a = service.GetCustomer(1);
Assert.AreEqual(c.FirstName, a.FirstName);
Assert.AreEqual(c.LastName, a.LastName);
}
Personally, I don’t mock these. I create, test and cleanup directly. This has helped me catch problem that are more real world scenarios when dealing with the database. Mocking is fantastic for testing integrations where you may not have access to a resource like a DB. If this is your case, then you may have no choice. Hope that helps.