Reputation: 4751
I want to test a functionality which includes a call to web service to get the data from database. The methods then operate on that data.
Now I want to write NUnit test cases for those methods. How can I assert results or values when I cannot know (at the time of writing cases) which data would be fetched at the run time?
Upvotes: 2
Views: 1383
Reputation: 6683
An excellent way of doing this is by inserting data (do it in the negative index range (assuming the negatives are not in use for production data)) run your tests with that dataset, and then roll back your transaction once you are done.
Another option that would help you test your datalayer better down the road, it to make a wrapping interface for your database layer. You can then mock that interface when you are running tests that need it.
Normally you might have your IDataReader object and call IdataReader.GetMeData and it would return the result set from the DB. In this case you would mock it (I use Rhino Mocks) and tell it to return your set of test data when GetMeData is called. p.s. Don't forget to use dependency injection to pass in the mock database access object.
Upvotes: 2