In a typical 3-layer architecture application, there are:
I am thinking of test the DAL (especially the one with Entity Framework) without using the real DB. But it's kind of difficult to simulate the complex foreign key constraints in DB. And also a lot of other things.
I am now thinking if this is the right way to Unit Test the DAL? Or which layer is most subject to Unit Testing?
I see some articles trying to mock the DbContext in the Entity Framework. It seems difficult to simulate the foreign key relations with this approach. I am wondering if it is the right location for the seam. Can we mock at somewhere else? Such as mocking around the ADO.NET layer? i.e. An in-memory mock DB for ADO.NET to consume.
Mocking database stuff is notoriously hard, time-consuming and cumbersome. Therefore, a more practical approach would be to setup a test database, let your test run against it, and test the entire persistence thing in combination - this is not exactly unit testing, but far more practical...
Btw.: The typical 3-layer architecture is: