CSHARP-666: Added lots of unit tests and fixed a few bugs.
CSHARP-689: Added missing paramName argument to calls to ArgumentOutOfRangeException.