[Digression] This post has been sitting in a somewhat unfinished state for a long time. It feels good to finally post it!
In rewriting my baseball game, CSFBL, I made the decision to use Castle ActiveRecord (built on top of NHibernate) to handle the persistence of my domain model. As a result, I needed to find a simple but effective way to unit test this implementation.
The unit tests needed to accomplish the following:
- Test the initialization of ActiveRecord (which validates the database schema against the object mappings).
- Test object validation (since I am using Castle’s Validation component and the
ActiveRecordValidationBase<T>
base class). - Ensure that a domain object can be persisted to the database.
- Ensure that a domain object can be retrieved from the database.
- Ensure that multiple instances of an object with the same persisted primary key are equal.
How, then, do we do this? Continue reading