I am having trouble writing a unit test for a method that uses Mongo Driver BulkWriteAsync().
The return for BulkWriteAsync() is BulkWriteResult which is an abstract class and I am not able to mock it. So I create a concrete class call MockBulkWriteResult which inherits BulkWriteResult.
Here is a sample code:
var response = new MockBulkWriteResult(5);
var mockCollection = new Mock<IMongoCollection<Dto>>(); mockCollection .Setup(x => x.BulkWriteAsync( It.IsAny<List<WriteModel<HierarchyDto>>>(), It.IsAny<BulkWriteOptions>(), It.IsAny<CancellationToken>())) .Returns(Task.FromResult(response));