2014-05-11 54 views
0

根据代码文档MongoServer.GetDatabaseMongoServer.GetDatabase不返回同一个实例

获取表示该服务器上的数据库MongoDatabase实例。 只有一个实例为数据库 设置每个组合创建。

但是,下面的测试失败(我得到一个不同的实例回来,尽管数据库名称相同):

void describe_get_database() 
{ 
    MongoServer server = null; 
    MongoDatabase db = null; 
    MongoDatabase db2 = null; 
    string dbName = null; 

    before =() => 
    { 
     var client = new MongoClient("mongodb://localhost"); 
     server = client.GetServer(); 

     dbName = "test"; 
     db = server.GetDatabase(dbName); 
    }; 

    act =() => db2 = server.GetDatabase(dbName); 

    context["when the database name is the same"] =() => 
    { 
     it["should return the same database instance"] = 
      () => db2.should_be_same(db); 
    }; 
} 

我有没有误解的文件?

回答

0

我和Ben的观察和问题,在这个问题上达成一致。

我连挖入蒙戈C#驱动程序的源代码在[https://searchcode.com/codesearch/view/26539464/],并没有显示出所创建只有一个实例的线索。

/// <summary> 
    /// Gets a MongoDatabase instance representing a database on this server. Only one instance 
    /// is created for each combination of database settings. 
    /// </summary> 
    /// <param name="databaseName">The name of the database.</param> 
    /// <param name="databaseSettings">The settings to use with this database.</param> 
    /// <returns>A new or existing instance of MongoDatabase.</returns> 
    public virtual MongoDatabase GetDatabase(string databaseName, MongoDatabaseSettings databaseSettings) 
    { 
     if (databaseName == null) 
     { 
      throw new ArgumentNullException("databaseName"); 
     } 
     if (databaseSettings == null) 
     { 
      throw new ArgumentNullException("databaseSettings"); 
     } 
     return new MongoDatabase(this, databaseName, databaseSettings); 
    } 
相关问题