CSHARP-666: Added lots of unit tests and fixed a few bugs.