我正在使用Moq在ASP.NETCore项目中模拟我的对象。我想模拟以下IsConnection()方法:publicClient(IMongoClientclient){_client=client;}publicasyncTaskIsConectionOk(){varpingCommand=newBsonDocument("ping",1);varmongoDb=_client.GetDatabase("Name");varcommandResult=awaitmongoDb.RunCommandAsync(pingCommand);returncommandResult!=nul
我使用C#MongoDB.Driver库连接到MongoDB。一些有效的代码MongoClientclient=MongoClientBuilder.Build("77.199.99.90",27016,"admin","pwd");IReadOnlyListdbNames=this.client.GetDatabaseNamesAsync().Result;foreach(vardbnindbNames){IMongoDatabasemongoDb=client.GetDatabase(dbn);varcNames=mongoDb.GetCollectionNamesAsync().
当我使用FindOne时,它说“'MongoClientExtensions.GetServer(MongoClient)'isobsolete:'UsethenewAPIinstead.'Observer.Client”作为警告。这是我的代码collection.EnsureIndex(IndexKeys.Ascending("Username","Type"),IndexOptions.SetUnique(true));varuserlog=collection.FindOne(Query.Where(ul=>ul.Username==username&&ul.Type==ty