Instead of bullying MongoDB, you should make fun of the layer on top of MongoDB.
You might want to consider an interface that provides operations in your repository that are incompatible with the underlying data store. For example, you may need an interface that abstracts operations on Student types, for example:
public interface IStudentOperations { void Add(Student student); }
When you create other dependencies, you add instances of the above interface or select any higher level abstractions.
The fact is that you are not opening MongoDB directly.
Once you do this, you can scoff at the interfaces you create, having one implementation for testing against a mock implementation, and then the actual implementation with its own tests to verify that the operations on the implementation are correct when the main implementation is done using MongoDB.
While you can definitely mock most MongoDB classes (as virtual methods) , you benefit from persistence of persistence; if you want to switch to say CouchDB or elasticsearch, you do not need to change the calls to these interfaces, you just create a new implementation.
Since you are trying to test the implementation of the repository , then you are usually fine, as mentioned earlier, most of the features of MongoDB virtual , which is friendly to most mocking libraries.
However, you will need to make sure that you pass MongoDatabase to your repository (do not create it in the repository) so that in your unit tests you can create the appropriate layout and then transfer it to your repository for testing.
casperOne
source share