Clone() public method

Creates a clone of the settings.
public Clone ( ) : MongoServerSettings
return MongoServerSettings
        public void TestAll()
        {
            var settings = new MongoServerSettings();
            settings.ConnectionMode = ConnectionMode.ReplicaSet;
            settings.ConnectTimeout = TimeSpan.FromSeconds(1);
            settings.DefaultCredentials = MongoCredentials.Create("username", "password");
            settings.MaxConnectionIdleTime = TimeSpan.FromSeconds(2);
            settings.MaxConnectionLifeTime = TimeSpan.FromSeconds(3);
            settings.MaxConnectionPoolSize = 99;
            settings.MinConnectionPoolSize = 11;
            settings.ReplicaSetName = "replicaname";
            settings.SafeMode = SafeMode.Create(5, TimeSpan.FromSeconds(4));
            settings.Server = new MongoServerAddress("server");
            settings.SlaveOk = true;
            settings.SocketTimeout = TimeSpan.FromSeconds(5);
            settings.WaitQueueSize = 55;
            settings.WaitQueueTimeout = TimeSpan.FromSeconds(6);

            Assert.AreEqual(ConnectionMode.ReplicaSet, settings.ConnectionMode);
            Assert.AreEqual(TimeSpan.FromSeconds(1), settings.ConnectTimeout);
            Assert.AreEqual(MongoCredentials.Create("username", "password"), settings.DefaultCredentials);
            Assert.AreEqual(TimeSpan.FromSeconds(2), settings.MaxConnectionIdleTime);
            Assert.AreEqual(TimeSpan.FromSeconds(3), settings.MaxConnectionLifeTime);
            Assert.AreEqual(99, settings.MaxConnectionPoolSize);
            Assert.AreEqual(11, settings.MinConnectionPoolSize);
            Assert.AreEqual("replicaname", settings.ReplicaSetName);
            Assert.AreEqual(SafeMode.Create(5, TimeSpan.FromSeconds(4)), settings.SafeMode);
            Assert.AreEqual(new MongoServerAddress("server"), settings.Server);
            Assert.IsTrue((new[] { new MongoServerAddress("server") }).SequenceEqual(settings.Servers));
            Assert.AreEqual(TimeSpan.FromSeconds(5), settings.SocketTimeout);
            Assert.AreEqual(55, settings.WaitQueueSize);
            Assert.AreEqual(TimeSpan.FromSeconds(6), settings.WaitQueueTimeout);

            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());

            var clone = settings.Clone();
            Assert.IsFalse(clone.IsFrozen);
            Assert.AreEqual(settings, clone);
        }
        public void TestEquals()
        {
            var settings = new MongoServerSettings();
            var clone = settings.Clone();
            Assert.IsTrue(clone.Equals(settings));

            clone = settings.Clone();
            clone.ConnectionMode = ConnectionMode.Direct;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ConnectTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.Credentials = new[] { MongoCredential.CreateMongoCRCredential("db2", "user2", "password2") };
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.Credentials = new[] { MongoCredential.CreateMongoCRCredential("db1", "user2", "password2") };
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.GuidRepresentation = GuidRepresentation.PythonLegacy;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.IPv6 = !settings.IPv6;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MaxConnectionIdleTime = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MaxConnectionLifeTime = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MaxConnectionPoolSize = settings.MaxConnectionPoolSize + 1;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.MinConnectionPoolSize = settings.MinConnectionPoolSize + 1;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ReadPreference = ReadPreference.Secondary;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.ReplicaSetName = "abc";
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.SecondaryAcceptableLatency = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.Server = new MongoServerAddress("someotherhost");
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.SocketTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.SslSettings = new SslSettings { CheckCertificateRevocation = false };
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.UseSsl = !settings.UseSsl;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.VerifySslCertificate = !settings.VerifySslCertificate;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.WaitQueueSize = settings.WaitQueueSize + 1;
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.WaitQueueTimeout = new TimeSpan(1, 2, 3);
            Assert.IsFalse(clone.Equals(settings));

            clone = settings.Clone();
            clone.WriteConcern = WriteConcern.W2;
            Assert.IsFalse(clone.Equals(settings));
        }
        public void TestDefaults()
        {
            var settings = new MongoServerSettings();
            Assert.AreEqual(ConnectionMode.Direct, settings.ConnectionMode);
            Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);
            Assert.AreEqual(null, settings.DefaultCredentials);
            Assert.AreEqual(MongoDefaults.MaxConnectionIdleTime, settings.MaxConnectionIdleTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);
            Assert.AreEqual(MongoDefaults.MaxConnectionPoolSize, settings.MaxConnectionPoolSize);
            Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, settings.MinConnectionPoolSize);
            Assert.AreEqual(null, settings.ReplicaSetName);
            Assert.AreEqual(SafeMode.False, settings.SafeMode);
            Assert.AreEqual(null, settings.Server);
            Assert.AreEqual(null, settings.Servers);
            Assert.AreEqual(MongoDefaults.SocketTimeout, settings.SocketTimeout);
            Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, settings.WaitQueueSize);
            Assert.AreEqual(MongoDefaults.WaitQueueTimeout, settings.WaitQueueTimeout);

            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());

            var clone = settings.Clone();
            Assert.IsFalse(clone.IsFrozen);
            Assert.AreEqual(settings, clone);
        }