craiggwilson / Simple.Data.MongoDB

MongoDB adapter for Simple.Data
35 stars 10 forks source link

FindById & empty results #3

Closed martinrue closed 13 years ago

martinrue commented 13 years ago

Hi Craig,

I've been getting an error when calling db.Users.FindById(x) where x points to an id that can't be found. I was expecting it to return null, but instead I was seeing an exception due to the .ToDictionary() extension being called on a null document instance.

Your original test (https://github.com/craiggwilson/Simple.Data.MongoDB/blob/master/Simple.Data.MongoDBTest/FindTests.cs#L26) passes because the data can be found, but it wasn't returning null when the database was empty or the result couldn't be found (i.e. invalid id).

I've put a null check on the .ToDictionary() call and added a few tests to cover the expected behaviour when no data can be found (i.e. null for FindById and empty collections for FindAllByX).

The problem might be more than I've trivially looked into, but I hope this helps.