I’ve nabbed some code from here: http://web.archive.org/web/20090407010431/http://code.jesschadwick.com/Snippets/TestDatabase.cs.
This seems to be an ideal scenario for me to set up tests against an actual db.
I’m new to unit tests, mocking etc, and so far I lack the understanding to work out why the Initialize_executes_schema_if_provided test fails.
I’ve tried a few variations around the code, switching Expect() to Setup(), and to Verify() both before and after attempting the initialisation, but no joy.
The ExecuteQuery method is virtual, so that should work as far as I can see – I can’t understand why it can’t verify that it is being called.
Any pointers would be really helpful.
Thanks all.
Because the Initialize method is virtual Moq overrides it with it’s own method implementation (which in this case does nothing). When db.Initialize() is called, Moq’s implementation is called, not the class under tests, which means the call to ExecuteQuery never happens and is why the test fails.