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


C# MongoUrl.ToString方法代碼示例

本文整理匯總了C#中MongoDB.Driver.MongoUrl.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# MongoUrl.ToString方法的具體用法?C# MongoUrl.ToString怎麽用?C# MongoUrl.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB.Driver.MongoUrl的用法示例。


在下文中一共展示了MongoUrl.ToString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestDefaults

        public void TestDefaults()
        {
            string connectionString = "mongodb://localhost";
            MongoUrl url = new MongoUrl(connectionString);
            Assert.IsNull(url.DefaultCredentials);
            Assert.AreEqual(1, url.Servers.Count());
            Assert.AreEqual("localhost", url.Servers.Single().Host);
            Assert.AreEqual(27017, url.Servers.Single().Port);
            Assert.IsNull(url.DatabaseName);
            Assert.AreEqual(ConnectionMode.Automatic, url.ConnectionMode);
            Assert.AreEqual(MongoDefaults.ConnectTimeout, url.ConnectTimeout);
            Assert.AreEqual(MongoDefaults.GuidRepresentation, url.GuidRepresentation);
            Assert.AreEqual(false, url.IPv6);
            Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, url.MaxConnectionIdleTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, url.MaxConnectionLifeTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, url.MaxConnectionPoolSize);
            Assert.AreEqual(null, url.ReplicaSetName);
            Assert.AreEqual(null, url.SafeMode);
            Assert.AreEqual(MongoDefaults.SecondaryAcceptableLatency, url.SecondaryAcceptableLatency);
#pragma warning disable 618
            Assert.AreEqual(false, url.SlaveOk);
#pragma warning restore
            Assert.AreEqual(MongoDefaults.SocketTimeout, url.SocketTimeout);
            Assert.AreEqual(false, url.UseSsl);
            Assert.AreEqual(MongoDefaults.WaitQueueMultiple, url.WaitQueueMultiple);
            Assert.AreEqual(MongoDefaults.WaitQueueSize, url.WaitQueueSize);
            Assert.AreEqual(MongoDefaults.WaitQueueTimeout, url.WaitQueueTimeout);
            Assert.AreEqual(connectionString, url.ToString());
        }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:29,代碼來源:MongoUrlTests.cs

示例2: TestConnectTimeout

        public void TestConnectTimeout()
        {
            string connectionString = "mongodb://localhost/?connectTimeout=123";
            MongoUrl url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromSeconds(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString + "s", url.ToString()); // "s" units added

            connectionString = "mongodb://localhost/?connectTimeout=123ms";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromMilliseconds(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeout=123s";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromSeconds(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeout=123m";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromMinutes(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeout=123h";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromHours(123), url.ConnectTimeout);
            Assert.AreEqual(connectionString, url.ToString());

            connectionString = "mongodb://localhost/?connectTimeoutMS=123";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(TimeSpan.FromMilliseconds(123), url.ConnectTimeout);
            Assert.AreEqual("mongodb://localhost/?connectTimeout=123ms", url.ToString()); // changed to "ms" suffix
        }
開發者ID:vshlos,項目名稱:mongo-csharp-driver,代碼行數:32,代碼來源:MongoUrlTests.cs

示例3: TestHostWithPort

 public void TestHostWithPort() {
     string connectionString = "mongodb://mongo.xyz.com:12345";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.IsNull(url.DefaultCredentials);
     Assert.AreEqual(1, url.Servers.Count());
     Assert.AreEqual("mongo.xyz.com", url.Servers.Single().Host);
     Assert.AreEqual(12345, url.Servers.Single().Port);
     Assert.AreEqual(ConnectionMode.Direct, url.ConnectionMode);
     Assert.AreEqual(null, url.ReplicaSetName);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:ebix,項目名稱:mongo-csharp-driver,代碼行數:11,代碼來源:MongoUrlTests.cs

示例4: TestConnectionMode

        public void TestConnectionMode()
        {
            string connectionString = "mongodb://localhost/?connect=direct";
            MongoUrl url = new MongoUrl(connectionString);
            Assert.AreEqual(ConnectionMode.Direct, url.ConnectionMode);
            Assert.AreEqual("mongodb://localhost", url.ToString()); // connect=direct dropped

            connectionString = "mongodb://localhost/?connect=replicaSet";
            url = new MongoUrl(connectionString);
            Assert.AreEqual(ConnectionMode.ReplicaSet, url.ConnectionMode);
            Assert.AreEqual(connectionString, url.ToString());
        }
開發者ID:vshlos,項目名稱:mongo-csharp-driver,代碼行數:12,代碼來源:MongoUrlTests.cs

示例5: TestAll

 public void TestAll()
 {
     string connectionString = "mongodb://localhost/?connect=replicaSet;replicaSet=name;slaveOk=true;safe=true;fsync=true;w=2;wtimeout=2s";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.IsNull(url.DefaultCredentials);
     Assert.AreEqual(1, url.Servers.Count());
     Assert.AreEqual("localhost", url.Server.Host);
     Assert.AreEqual(27017, url.Server.Port);
     Assert.AreEqual(null, url.DatabaseName);
     Assert.AreEqual(ConnectionMode.ReplicaSet, url.ConnectionMode);
     Assert.AreEqual("name", url.ReplicaSetName);
     Assert.AreEqual(SafeMode.Create(true, true, 2, TimeSpan.FromSeconds(2)), url.SafeMode);
     Assert.AreEqual(true, url.SlaveOk);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:jenrom,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:MongoUrlTests.cs

示例6: TestDirectConnectionMode

 public void TestDirectConnectionMode()
 {
     string connectionString = "mongodb://localhost/?connect=direct";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.IsNull(url.Credentials);
     Assert.AreEqual(1, url.Servers.Count());
     Assert.AreEqual("localhost", url.Server.Host);
     Assert.AreEqual(27017, url.Server.Port);
     Assert.AreEqual(null, url.DatabaseName);
     Assert.AreEqual(ConnectionMode.Direct, url.ConnectionMode);
     Assert.AreEqual(null, url.ReplicaSetName);
     Assert.AreEqual(SafeMode.False, url.SafeMode);
     Assert.AreEqual(false, url.SlaveOk);
     Assert.AreEqual("mongodb://localhost", url.ToString()); // connect=direct dropped
 }
開發者ID:kenegozi,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:MongoUrlTests.cs

示例7: TestHost

 public void TestHost()
 {
     string connectionString = "mongodb://mongo.xyz.com";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.IsNull(url.Credentials);
     Assert.AreEqual(1, url.Servers.Count());
     Assert.AreEqual("mongo.xyz.com", url.Servers.Single().Host);
     Assert.AreEqual(27017, url.Servers.Single().Port);
     Assert.IsNull(url.DatabaseName);
     Assert.AreEqual(ConnectionMode.Direct, url.ConnectionMode);
     Assert.AreEqual(null, url.ReplicaSetName);
     Assert.AreEqual(SafeMode.False, url.SafeMode);
     Assert.AreEqual(false, url.SlaveOk);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:kenegozi,項目名稱:mongo-csharp-driver,代碼行數:15,代碼來源:MongoUrlTests.cs

示例8: TestAll

 public void TestAll()
 {
     string connectionString = "mongodb://localhost/?connect=replicaSet;replicaSet=name;readPreference=secondary;safe=true;fsync=true;w=2;wtimeout=2s;guids=PythonLegacy";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.IsNull(url.DefaultCredentials);
     Assert.AreEqual(1, url.Servers.Count());
     Assert.AreEqual("localhost", url.Server.Host);
     Assert.AreEqual(27017, url.Server.Port);
     Assert.AreEqual(null, url.DatabaseName);
     Assert.AreEqual(ConnectionMode.ReplicaSet, url.ConnectionMode);
     Assert.AreEqual("name", url.ReplicaSetName);
     Assert.AreEqual(GuidRepresentation.PythonLegacy, url.GuidRepresentation);
     Assert.AreEqual(SafeMode.Create(true, true, 2, TimeSpan.FromSeconds(2)), url.SafeMode);
     Assert.AreEqual(ReadPreference.Secondary, url.ReadPreference);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:kamaradclimber,項目名稱:mongo-csharp-driver,代碼行數:16,代碼來源:MongoUrlTests.cs

示例9: TestDefaults

 public void TestDefaults() {
     string connectionString = "mongodb://localhost";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.IsNull(url.DefaultCredentials);
     Assert.AreEqual(1, url.Servers.Count());
     Assert.AreEqual("localhost", url.Servers.Single().Host);
     Assert.AreEqual(27017, url.Servers.Single().Port);
     Assert.IsNull(url.DatabaseName);
     Assert.AreEqual(ConnectionMode.Direct, url.ConnectionMode);
     Assert.AreEqual(MongoDefaults.ConnectTimeout, url.ConnectTimeout);
     Assert.AreEqual(false, url.IPv6);
     Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, url.MaxConnectionIdleTime);
     Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, url.MaxConnectionLifeTime);
     Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, url.MaxConnectionPoolSize);
     Assert.AreEqual(null, url.ReplicaSetName);
     Assert.AreEqual(SafeMode.False, url.SafeMode);
     Assert.AreEqual(false, url.SlaveOk);
     Assert.AreEqual(MongoDefaults.SocketTimeout, url.SocketTimeout);
     Assert.AreEqual(MongoDefaults.WaitQueueMultiple, url.WaitQueueMultiple);
     Assert.AreEqual(MongoDefaults.WaitQueueSize, url.WaitQueueSize);
     Assert.AreEqual(MongoDefaults.WaitQueueTimeout, url.WaitQueueTimeout);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:ebix,項目名稱:mongo-csharp-driver,代碼行數:23,代碼來源:MongoUrlTests.cs

示例10: TestReplicaSetName

 public void TestReplicaSetName()
 {
     string connectionString = "mongodb://localhost/?replicaSet=name";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.AreEqual(ConnectionMode.Automatic, url.ConnectionMode);
     Assert.AreEqual("name", url.ReplicaSetName);
     Assert.AreEqual("mongodb://localhost/?replicaSet=name", url.ToString());
 }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:MongoUrlTests.cs

示例11: TestMinConnectionPoolSize

 public void TestMinConnectionPoolSize()
 {
     string connectionString = "mongodb://localhost/?minPoolSize=123";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.AreEqual(123, url.MinConnectionPoolSize);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:MongoUrlTests.cs

示例12: TestAll

        public void TestAll()
        {
            string connectionString = "mongodb://localhost/?connect=replicaSet;replicaSet=name;slaveOk=true;safe=true;fsync=true;w=2;wtimeout=2s;secondaryAcceptableLatency=12s;uuidRepresentation=PythonLegacy";
            MongoUrl url = new MongoUrl(connectionString);
            Assert.IsNull(url.DefaultCredentials);
            Assert.AreEqual(1, url.Servers.Count());
            Assert.AreEqual("localhost", url.Server.Host);
            Assert.AreEqual(27017, url.Server.Port);
            Assert.AreEqual(null, url.DatabaseName);
            Assert.AreEqual(ConnectionMode.ReplicaSet, url.ConnectionMode);
            Assert.AreEqual("name", url.ReplicaSetName);
            Assert.AreEqual(GuidRepresentation.PythonLegacy, url.GuidRepresentation);
            Assert.AreEqual(SafeMode.Create(true, true, 2, TimeSpan.FromSeconds(2)), url.SafeMode);
            Assert.AreEqual(TimeSpan.FromSeconds(12), url.SecondaryAcceptableLatency);
#pragma warning disable 618
            Assert.AreEqual(true, url.SlaveOk);
#pragma warning restore
            Assert.AreEqual(connectionString, url.ToString());
        }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:19,代碼來源:MongoUrlTests.cs

示例13: TestWaitQueueSize

 public void TestWaitQueueSize()
 {
     string connectionString = "mongodb://localhost/?waitQueueSize=123";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.AreEqual(0, url.WaitQueueMultiple);
     Assert.AreEqual(123, url.WaitQueueSize);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:8,代碼來源:MongoUrlTests.cs

示例14: TestSlaveOkTrue

        public void TestSlaveOkTrue()
        {
            string connectionString = "mongodb://localhost/?slaveOk=true";
            MongoUrl url = new MongoUrl(connectionString);
#pragma warning disable 618
            Assert.AreEqual(true, url.SlaveOk);
#pragma warning restore
            Assert.AreEqual(connectionString, url.ToString());
        }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:9,代碼來源:MongoUrlTests.cs

示例15: TestSafeModeTrueFSyncTrueW2WTimeout

 public void TestSafeModeTrueFSyncTrueW2WTimeout()
 {
     string connectionString = "mongodb://localhost/?safe=true;fsync=true;w=2;wtimeout=2s";
     MongoUrl url = new MongoUrl(connectionString);
     Assert.AreEqual(SafeMode.Create(true, true, 2, TimeSpan.FromSeconds(2)), url.SafeMode);
     Assert.AreEqual(connectionString, url.ToString());
 }
開發者ID:staywellandy,項目名稱:mongo-csharp-driver,代碼行數:7,代碼來源:MongoUrlTests.cs


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