I'm creating some unit tests for my DAL that uses mongoDB c# driver. The thing is that I have this method that I want to test:
public async virtual Task<IEnumerable<T>> GetAsync(Expression<Func<T, bool>> predicate)
{
return (await Collection.FindAsync(predicate)).ToList();
}
and using Moq I have mocked the collection like this:
var mockMongoCollectionAdapter = new Mock<IMongoCollectionAdapter<Entity>>();
var expectedEntities = new List<Entity>
{
mockEntity1.Object,
mockEntity2.Object
};
mockMongoCollectionAdapter.Setup(x => x.FindAsync(It.IsAny<Expression<Func<Entity,bool>>>(), null, default(CancellationToken))).ReturnsAsync(expectedEntities as IAsyncCursor<Entity>);
but as expectedEntities as IAsyncCursor<Entity>
is null the test is not working.
What is the best way to mock this method and handle the IAsyncCursor?