To do this correctly, you must use some dependency injection (DI), and for .NET a few. I am currently using the Unity Framework, but there are others that are easier.
Here is one link from this site to this topic, but there are others: Injecting dependencies in .NET with examples?
This will allow you to more easily make fun of other parts of your application by simply using the mock class to implement the interface so that you can control how it will respond. But it also means developing an interface.
Since you asked about best practices, this will be the one, IMO.
Then, without going to db, if you do not need, as expected, this is different.
If you need to test certain types of behavior, such as cascading deletion of a foreign key, you might want to write database tests for this, but as a rule, it is better not to go to a real database, because more than one person can run unit test for times, and if they go to the same database tests, they may fail because the expected data may change.
Edit: by unit test database, I mean this, since it is designed to use t-sql to do some configuration, testing and breaking. http://msdn.microsoft.com/en-us/library/aa833233%28VS.80%29.aspx
James Black Aug 02 '09 at 0:24 2009-08-02 00:24
source share