Hi,
I've gotton to the point in my simple project where I'm ready to unit test the DAL.
I basically have a class called FooDataAccess with several very simple functions, lets say 3 of them like this:
int InsertFoo(string fooName)
void UpdateFoo(int fooID, string fooName)
void InsertFoosDepedency(int fooID, string someValue)
What I did was this - put 4 SQL Scripts inside my unit test project, the last one as am embedded resource.
1) Create (Unit test) Database Script, 2) Create Objects Script, 3) Insert Lookup Table Values and 4) Delete All But Lookup Table Values
The idea is, anyone first using the project should manually run scripts 1-3 by hand as a one-time setup. Then execute script #4 on start-up of each unit test... (in small apps, you could even run all of them at the testing level)
OK, so far so good...
So I have my unit test database setup, as an empty slate. Testing the first function InsertFoo() is obviously very simple. I call the function, then just Assert(ExecuteSQL("select count(*) from foo") > 1), Assert(ExecuteSQL("select fooName from t_foo") = expected)), etc..
Where I'm a bit stuck is the ones which require dependencies, like the 3rd function in my example, or even the update.
Would it make sense to temporarily drop all foreign key constraints for the scope of my test? Otherwise, in order to unit test the InsertFoosDepedency(int fooID, string someValue) function, I would have to execute some arbitrary sql first (manually insert a record to the FOO table and return the FooID)...
OR, should I just do the latter?
Any and all feedback is greatly appreciated.
UPDATE: Its working cleanly with inline SQL to create the dependents. I guess I'm just looking for comments & critisism on this method for unit testing DAL. Thanks again