當前位置: 首頁>>代碼示例>>C#>>正文


C# Driver.MongoDatabaseSettings類代碼示例

本文整理匯總了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); });
 }
開發者ID:nickgervasi,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:MongoDatabaseTests.cs

示例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));
        }
開發者ID:narutoswj,項目名稱:mongo-csharp-driver,代碼行數:26,代碼來源:MongoDatabaseSettingsTests.cs

示例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());
        }
開發者ID:redforks,項目名稱:mongo-csharp-driver,代碼行數:25,代碼來源:MongoDatabaseSettingsTests.cs

示例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());
        }
開發者ID:nickgervasi,項目名稱:mongo-csharp-driver,代碼行數:26,代碼來源:MongoDatabaseSettingsTests.cs

示例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);
 }
開發者ID:fir3pho3nixx,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:MongoDatabaseSettingsTests.cs

示例6: GetDatabase

 public static IMongoDatabase GetDatabase(string database, MongoDatabaseSettings dbSettings = null)
 {
     if(string.IsNullOrWhiteSpace(database))
         throw new ArgumentNullException("database");
     
     return Client.GetDatabase(database, dbSettings);
 }
開發者ID:pdlg-spotlight,項目名稱:lambda-architecture,代碼行數:7,代碼來源:MongoDBManager.cs

示例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));
        }
開發者ID:bollinim,項目名稱:mongo-csharp-driver,代碼行數:26,代碼來源:MongoDatabaseSettingsTests.cs

示例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));
        }
開發者ID:Nakro,項目名稱:mongo-csharp-driver,代碼行數:32,代碼來源:MongoDatabaseSettingsTests.cs

示例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));
        }
開發者ID:mingezhao,項目名稱:PersonalTools,代碼行數:9,代碼來源:DataStore.cs

示例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
 }
開發者ID:NileshGokhale,項目名稱:samplecode,代碼行數:12,代碼來源:UnitOfWork.cs

示例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);
        }
開發者ID:Nakro,項目名稱:mongo-csharp-driver,代碼行數:10,代碼來源:MongoDatabaseSettingsTests.cs

示例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);
 }
開發者ID:nickgervasi,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:MongoDatabaseSettingsTests.cs

示例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;
 }
開發者ID:geffzhang,項目名稱:Rebus,代碼行數:11,代碼來源:MongoTestHelper.cs

示例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);
 }
開發者ID:bollinim,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:MongoDatabaseImplTests.cs

示例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);
 }
開發者ID:CurufinweU,項目名稱:dotnet,代碼行數:12,代碼來源:ProfiledMongoServer.cs


注:本文中的MongoDB.Driver.MongoDatabaseSettings類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。