Finished unit tests

There is still some code that should be covered by unit tests, but needs to be decoupled from database drivers first.