How do i test my code (TDD) for standard CRUD procedures without getting a database. Can you really achieve such degree of isolation to ensure that my code is database independent.
Yep. You are writing an Interface with the call towards the database you'd want.
Then you definitely create two classes that implement the interface.
You have real use of your database.
Another, just pretends, it is a mock implementation.
Use knockoffs, like Rhino Mocks, to mock the information access. This way whenever your tests run they'll communicate with the fake rather than going completely lower towards the database.
You can look at the company layer (and a few of the presentation layer) using Mock objects.
Use Mocks/Knockoffs to ensure that rather than calling the database in the DAL an imitation class is going to be known as rather and return a predefined value.
To be able to test the DAL you'll need actual database. Use a unit testing framework to operate simple CRUD around the database. Produce a simple test database in addition to a restore point and employ the system testing framework's setup &lifier teardown to make certain your database is incorporated in the expected condition.
How do i test my code (TDD) for standard CRUD procedures without getting a database.
I observe that the publish is labeled with nunit, and so i assume b .internet context. Considering that, I have personally utilized SQLite being an in-memory database effectively inside a work for a couple of several weeks time now (along with NHibernate and customary DDD-designs).
Can you really achieve such level of isolation to ensure that my code is database independent.
I do not think that you could write fully database independent code, but NHibernate takes me 95% of how there (but time is dependent heavily in your specific context).
In addition, with good data-access designs, e.g. «Repository» and «Unit of Work», the relaxation from the code base can be created 100% database agnostic. You have to other data sources, e.g. CSV and XML files.