public void TestGetCredentials() { var settings = new MongoServerSettings(); var credentialsStore = new MongoCredentialsStore(); credentialsStore.AddCredentials("db1", new MongoCredentials("user1", "password1")); credentialsStore.AddCredentials("db2", new MongoCredentials("user2", "password2")); settings.CredentialsStore = credentialsStore; Assert.AreEqual(new MongoCredentials("user1", "password1"), settings.GetCredentials("db1")); Assert.AreEqual(new MongoCredentials("user2", "password2"), settings.GetCredentials("db2")); Assert.AreEqual(null, settings.GetCredentials("db3")); Assert.AreEqual(null, settings.GetCredentials("admin")); var defaultCredentials = new MongoCredentials("defaultuser", "defaultpassword"); settings.DefaultCredentials = defaultCredentials; Assert.AreEqual(defaultCredentials, settings.GetCredentials("db3")); Assert.AreEqual(null, settings.GetCredentials("admin")); // default credentials aren't admin credentials defaultCredentials = new MongoCredentials("defaultuser", "defaultpassword", true); settings.DefaultCredentials = defaultCredentials; Assert.AreEqual(defaultCredentials, settings.GetCredentials("db3")); Assert.AreEqual(defaultCredentials, settings.GetCredentials("admin")); // default credentials are admin credentials }