Otis wrote:
By writing a test that assumes the save went OK. You're doing that now anyway. Deletes are rather easy, but how are you going to mock a prefetch path fetch of multiple nodes, or a hierarchical save action? the question then becomes: what is the reason for the test: to test your business logic (I would say so) or to test also if our code works.
While I appreciate you testing our code again, you could say the tests you're writing are mainly meant to test whether your application code itself works.
So either skip the DB or include it in full, as only then you'll find bugs related to null values, UC violations, FK violations etc.
I'll try and clarify,
Yes this is about testing our business logic, I personally prefer to include the DB in full when I do this, probably because I spend a lot of my time in the DAL where I have no choice but to test against a DB and for the reasons you stated. But the rest of my team spend there time in the UI layer and generally prefer to skip the DB all together in their tests, which is fair enough I guess. However the way our DAL is structured skipping the DB is not easy and one guy in particular has gone as far as using @*&@# moles(to mock static methods) and a pseudo repository pattern to skip the DB which is ridiculous.
Anyway so I'm trying to meet them half way by letting them skip the DB (for DML at least) at the adapter level. At the very least this simply does nothing when a save is called, but as you alluded to there might be application code which relies on state change in the entity after the save, I think in most cases you could use a mock setup to set that state. The next thing you might want to verify is that the save was actually called, which you can do with something like
mockDataAccessAdapter.Verify(daa => daa.SaveEntity(occurrenceEntity), Times.Once());
or if the state was set by the mock you could check that.
Verifying the save was called is a secondary consideration.
That’s DML anyway, for the query side I seriously doubt whether you could substitute anything but a basic Linq query with a result set at the adapter level but I haven't thought much about it yet.
To my mind all queries need to be tested and tested against a db, but I guess you could argue a fetch-all-entities Linq query or a simple one entity fetch doesn't need to be tested so can be safely mocked out and substituted with some test data.
I have no interest in testing your code (except when I hit a bug of course
) but I do wan't verification that our queries are correct e.g. if someone removes a where clause when they shouldn't a test should fail.
Otis wrote:
I can refactor the call away for you, but it won't be in v3.1, it will be v3.5
Sure, great - that's the best I could hope for.