Support closing the database
Add first unit tests

These check the lowest-layer of the database code.