Extracted new, testable methods.

Previously, these methods were embedded in database connection code and
untestable.
Added DI-friendly constructor.
Make methods more defensive.
Better variable names.
Even better variable names!
Added a number of new unit tests.
Fixed order of Asset.Equal arguments. Oops!
Added unit tests for two new methods.