Moved unit testing into its own file

Moved the existing database unit testing to its own file and added any
remaining unit tests.