本文整理汇总了C#中MongoDB.Driver.MongoDatabaseSettings类的典型用法代码示例。如果您正苦于以下问题:C# MongoDatabaseSettings类的具体用法?C# MongoDatabaseSettings怎么用?C# MongoDatabaseSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoDatabaseSettings类属于MongoDB.Driver命名空间,在下文中一共展示了MongoDatabaseSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConstructorArgumentChecking
public void TestConstructorArgumentChecking()
{
var settings = new MongoDatabaseSettings(_server, "");
Assert.Throws<ArgumentNullException>(() => { new MongoDatabase(null, settings); });
Assert.Throws<ArgumentNullException>(() => { new MongoDatabase(_server, null); });
Assert.Throws<ArgumentOutOfRangeException>(() => { new MongoDatabase(_server, settings); });
}
示例2: TestEquals
public void TestEquals()
{
var settings = new MongoDatabaseSettings();
var clone = settings.Clone();
Assert.IsTrue(clone.Equals(settings));
settings.Freeze();
clone.Freeze();
Assert.IsTrue(clone.Equals(settings));
clone = settings.Clone();
clone.GuidRepresentation = GuidRepresentation.PythonLegacy;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.ReadConcern = ReadConcern.Majority;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.ReadPreference = ReadPreference.Secondary;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.WriteConcern = WriteConcern.W2;
Assert.IsFalse(clone.Equals(settings));
}
示例3: TestAll
public void TestAll() {
var settings = new MongoDatabaseSettings(
"database",
MongoCredentials.Create("username", "password"),
GuidRepresentation.CSharpLegacy,
SafeMode.Create(5, TimeSpan.FromSeconds(5)),
true
);
Assert.AreEqual("database", settings.DatabaseName);
Assert.AreEqual(MongoCredentials.Create("username", "password"), settings.Credentials);
Assert.AreEqual(GuidRepresentation.CSharpLegacy, settings.GuidRepresentation);
Assert.AreEqual(SafeMode.Create(5, TimeSpan.FromSeconds(5)), settings.SafeMode);
Assert.AreEqual(true, settings.SlaveOk);
Assert.IsFalse(settings.IsFrozen);
var hashCode = settings.GetHashCode();
var stringRepresentation = settings.ToString();
Assert.AreEqual(settings, settings);
settings.Freeze();
Assert.IsTrue(settings.IsFrozen);
Assert.AreEqual(hashCode, settings.GetHashCode());
Assert.AreEqual(stringRepresentation, settings.ToString());
}
示例4: TestAll
public void TestAll()
{
var server = MongoServer.Create();
var settings = new MongoDatabaseSettings(server, "database")
{
Credentials = MongoCredentials.Create("username", "password"),
SafeMode = SafeMode.Create(5, TimeSpan.FromSeconds(5)),
ReadPreference = ReadPreference.Primary
};
Assert.AreEqual("database", settings.DatabaseName);
Assert.AreEqual(MongoCredentials.Create("username", "password"), settings.Credentials);
Assert.AreEqual(GuidRepresentation.CSharpLegacy, settings.GuidRepresentation);
Assert.AreEqual(SafeMode.Create(5, TimeSpan.FromSeconds(5)), settings.SafeMode);
Assert.AreEqual(ReadPreference.Primary, settings.ReadPreference);
Assert.IsFalse(settings.IsFrozen);
var hashCode = settings.GetHashCode();
var stringRepresentation = settings.ToString();
Assert.AreEqual(settings, settings);
settings.Freeze();
Assert.IsTrue(settings.IsFrozen);
Assert.AreEqual(hashCode, settings.GetHashCode());
Assert.AreEqual(stringRepresentation, settings.ToString());
}
示例5: TestConstructor
public void TestConstructor()
{
var settings = new MongoDatabaseSettings();
Assert.AreEqual(GuidRepresentation.Unspecified, settings.GuidRepresentation);
Assert.AreEqual(null, settings.ReadPreference);
Assert.AreEqual(null, settings.WriteConcern);
}
示例6: GetDatabase
public static IMongoDatabase GetDatabase(string database, MongoDatabaseSettings dbSettings = null)
{
if(string.IsNullOrWhiteSpace(database))
throw new ArgumentNullException("database");
return Client.GetDatabase(database, dbSettings);
}
示例7: TestEquals
public void TestEquals()
{
var settings = new MongoDatabaseSettings();
var clone = settings.Clone();
Assert.IsTrue(clone.Equals(settings));
settings.Freeze();
clone.Freeze();
Assert.IsTrue(clone.Equals(settings));
clone = settings.Clone();
clone.GuidRepresentation = GuidRepresentation.PythonLegacy;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.OperationTimeout = TimeSpan.FromMilliseconds(20);
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.ReadPreference = ReadPreference.Secondary;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.WriteConcern = WriteConcern.W2;
Assert.IsFalse(clone.Equals(settings));
}
示例8: TestEquals
public void TestEquals()
{
var settings = new MongoDatabaseSettings();
var clone = settings.Clone();
Assert.IsTrue(clone.Equals(settings));
settings.Freeze();
clone.Freeze();
Assert.IsTrue(clone.Equals(settings));
clone = settings.Clone();
clone.GuidRepresentation = GuidRepresentation.PythonLegacy;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.ReadPreference = ReadPreference.Secondary;
Assert.IsFalse(clone.Equals(settings));
#pragma warning disable 618
clone = settings.Clone();
clone.SafeMode = SafeMode.W2;
Assert.IsFalse(clone.Equals(settings));
clone = settings.Clone();
clone.SlaveOk = !settings.SlaveOk;
Assert.IsFalse(clone.Equals(settings));
#pragma warning restore
clone = settings.Clone();
clone.WriteConcern = WriteConcern.W2;
Assert.IsFalse(clone.Equals(settings));
}
示例9: Register
public static void Register(string databaseName, MongoDatabaseSettings settings = null)
{
if (_instance != null)
{
throw new Exception("Instance has been generated. Please call method DataStore.Instance for using");
}
_instance = new Lazy<DataStore>(() => new DataStore(databaseName, settings));
}
示例10: UnitOfWork
/// <summary>
/// Initializes a new instance of the <see cref="UnitOfWork"/> class.
/// </summary>
public UnitOfWork()
{
const string dbName = "GuestBook";
const string connectionString = "mongodb://localhost"; //TODO:USer App setting helper
var client = new MongoClient(connectionString);
var server = client.GetServer();
var settings = new MongoDatabaseSettings();
_database = server.GetDatabase(dbName, settings);//TODO:User app sertting helper
}
示例11: TestConstructor
public void TestConstructor()
{
var settings = new MongoDatabaseSettings();
Assert.AreEqual(GuidRepresentation.Unspecified, settings.GuidRepresentation);
Assert.AreEqual(null, settings.ReadPreference);
#pragma warning disable 618
Assert.AreEqual(null, settings.SafeMode);
#pragma warning restore
Assert.AreEqual(null, settings.WriteConcern);
}
示例12: TestFrozenCopy
public void TestFrozenCopy()
{
var server = MongoServer.Create();
var settings = new MongoDatabaseSettings(server, "database");
var frozenCopy = settings.FrozenCopy();
var secondFrozenCopy = frozenCopy.FrozenCopy();
Assert.AreNotSame(settings, frozenCopy);
Assert.AreSame(frozenCopy, secondFrozenCopy);
Assert.AreEqual(false, settings.IsFrozen);
Assert.AreEqual(true, frozenCopy.IsFrozen);
}
示例13: GetMongoDatabase
public static MongoDatabase GetMongoDatabase()
{
var url = GetUrl();
var settings = new MongoDatabaseSettings
{
GuidRepresentation = GuidRepresentation.Standard,
WriteConcern = WriteConcern.Acknowledged
};
var mongoDatabase = new MongoClient(url).GetServer().GetDatabase(url.DatabaseName, settings);
return mongoDatabase;
}
示例14: Setup
public void Setup()
{
var settings = new MongoDatabaseSettings();
settings.ApplyDefaultValues(new MongoClientSettings());
_operationExecutor = new MockOperationExecutor();
_subject = new MongoDatabaseImpl(
new DatabaseNamespace("foo"),
settings,
Substitute.For<ICluster>(),
_operationExecutor);
}
示例15: GetDatabase
public override MongoDatabase GetDatabase(string databaseName, MongoDatabaseSettings databaseSettings)
{
if (databaseName == null)
{
throw new ArgumentNullException("databaseName");
}
if (databaseSettings == null)
{
throw new ArgumentNullException("databaseSettings");
}
return new ProfiledMongoDatabase(this, databaseName, databaseSettings);
}