How to Mock MongoDB's GetCollection method

Viewed 322

I am using Moq for mocking purpose.

I am looking for mocking MongoDB's GetCollection method in C#. MongoDB's 2.7.0 driver is being used in the code.

var filter = ....; //my business logic

var filteredData = await _mongoDb.GetCollection<MongoResult>("someKey").FindAsync(filter);

The idea is to test the filter condition as part of the test case.

Thus, I am looking for mocking _mongoDb.GetCollection<MongoResult> so that I can pass in my custom collection and then filter can be tested.

I have tried approaches mentioned in different posts in Stack Overflow. However, none of them seem to work (so far).

0 Answers
Related