Как написать тестовый пример moq для макета функции BulkWrite и возврата BulkWriteResult?
public class DBRepository
{
public void SaveData()
{
List<WriteModel<Student>> writeModels = new List<WriteModel<Student>>();
foreach (var item in res)
{
writeModels.Add(new InsertOneModel<Student>(item));
}
BulkWriteResult writeResult = mongoDbProvider.GetCollection<Student>("Student").BulkWrite(writeModels);
}
}
public class mongoDbProvider
{
private IMongoClient client;
private IMongoDatabase database;
public DrugRebateDbProvider()
{
this.client = new MongoClient();
MongoUrl url = new MongoUrl("mongodb:\\localhost:27017\studentDB");
MongoClientSettings settings = MongoClientSettings.FromUrl(url);
this.client = new MongoClient(settings);
this.database = this.client.GetDatabase(url.DatabaseName);
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
{
return this.database.GetCollection<T>(collectionName);
}
}
Я попытался использовать следующий код для настройки макета и получил исключение
this.mockDbProvider.Setup(x => x.GetCollection<DataModel.AgingReport>(It.IsAny<string>()).BulkWrite(It.IsAny<IEnumerable<WriteModel<DataModel.AgingReport>>>(), It.IsAny<BulkWriteOptions>(), It.IsAny<CancellationToken>()));