I think you mean 'supposed to create your stored procedure first, then...' – Kirk Broadhurst Feb 11 at 2:55 Yep, thanks. - fixing – Adam Rackis Feb 11 at 2:58 If you mean manually add the stored procedure to the context then it wouldn't be an automated test. – Coder 2 Feb 11 at 2:58 I think you're confused.
The automation of your tests does not include automation of the creation of your DB objects. How could it? You're probably maintaining some sort of suite of scripts to create your database with.
One of those scripts will create your SPROC. Use those scripts to make a test DB, then write some tests against it. – Adam Rackis Feb 11 at 3:01 Well at the start of the unit test I create the database using datacontext.CreateDatabase() then populate it.
Then I run my unit tests – Coder 2 Feb 11 at 3:40.
The point of unit testing is not to touch your database, so if you have business logic based on the database, you need separate this dependency by using something like Repository pattern to return a value or values which you normally will get from the stored procedure.
1 He wants to actually unit test his SPROC. To do that he has to touch his database. Mocking your DB to provide specific results to test your business logic against is fine, but he wants to test the DB itself.
– Adam Rackis Feb 11 at 2:59 -1: please read carefully - he's testing the stored procedure, not the business logic. – John Saunders Feb 11 at 3:35 I think what this answer is hinting at, is this is an integration test, not a unit test. You cannot unit test a stored procedure.
You can unit test a Repository, but you should be providing mock objects. – RPM1984 Feb 11 at 3:45 This was a good answer given I had put it as unit test when I should really have been more clear and just written test. Have edited the question.
– Coder 2 Feb 11 at 3:45 1 @RPM: you can populate a clean database with data for the specific test, then call the SP with particular parameters, check the results, then roll back the DB changes. Perfect unit tests. I just got through with dozens of them.
– John Saunders Feb 11 at 3:53.
I think you're supposed to create your stored procedure first, then add it to your L2S context, then just call it in a unit test. Of course you'll want to set up a special test database first. Also, obviously, be sure to clean up your database after each test to minimize side effects between tests.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.