Given that most real world applications have fairly complicated relationships between entities, is there much value in testing individual class mappings? It seems that to be truly valuable, NHibernate tests should revolve around retrieving, persisting and deleting entire object graphs, starting at the aggregate root level (i.e. Customer-->Order-->OrderDetails). But if I go down that road, it seems I would have to test CRUD operations at every conceivable level in the object tree to validate that the "whole" works as expected; leading to an explosion of tests:
- Delete a Customer
- Delete an Order
- Delete an OrderItem
- Insert a Customer
- Insert an Order
- Insert an OrderItem
So, unless I'm missing something, which I very likely am, my choices are:
- Write one fixture suite per class/mapping
- Pros: Simpler to write CRUD operations
- Cons: Diminished test value, as they provide no assurance that entire aggregate roots are being persisted correctly
- Write one fixture suite per object graph
- Cons: Tests harder to write/explosion of test scenarios
- Pros: Higher value as tests since they test persistence from the application's perspective (i.e. testing mutations against the unified/integrated object graph)
If at all relevant, I'm using the NHibernate.Mapping.ByCode
ConventionModelMapper to generate mappings using conventions.