Freeze() public method

Freezes the settings.
public Freeze ( ) : MongoClientSettings
return MongoClientSettings
        public void TestConnectionMode()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(ConnectionMode.Automatic, settings.ConnectionMode);

            var connectionMode = ConnectionMode.Direct;
            settings.ConnectionMode = connectionMode;
            Assert.AreEqual(connectionMode, settings.ConnectionMode);

            settings.Freeze();
            Assert.AreEqual(connectionMode, settings.ConnectionMode);
            Assert.Throws<InvalidOperationException>(() => { settings.ConnectionMode = connectionMode; });
        }
        public void TestConnectTimeout()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout);

            var connectTimeout = new TimeSpan(1, 2, 3);
            settings.ConnectTimeout = connectTimeout;
            Assert.AreEqual(connectTimeout, settings.ConnectTimeout);

            settings.Freeze();
            Assert.AreEqual(connectTimeout, settings.ConnectTimeout);
            Assert.Throws<InvalidOperationException>(() => { settings.ConnectTimeout = connectTimeout; });
        }
        public void TestWaitQueueSize()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.ComputedWaitQueueSize, settings.WaitQueueSize);

            var waitQueueSize = 123;
            settings.WaitQueueSize = waitQueueSize;
            Assert.AreEqual(waitQueueSize, settings.WaitQueueSize);

            settings.Freeze();
            Assert.AreEqual(waitQueueSize, settings.WaitQueueSize);
            Assert.Throws<InvalidOperationException>(() => { settings.WaitQueueSize = waitQueueSize; });
        }
        public void TestVerifySslCertificate()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(true, settings.VerifySslCertificate);

            var verifySslCertificate = false;
            settings.VerifySslCertificate = verifySslCertificate;
            Assert.AreEqual(verifySslCertificate, settings.VerifySslCertificate);

            settings.Freeze();
            Assert.AreEqual(verifySslCertificate, settings.VerifySslCertificate);
            Assert.Throws<InvalidOperationException>(() => { settings.VerifySslCertificate = verifySslCertificate; });
        }
        public void TestUseSsl()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(false, settings.UseSsl);

            var useSsl = true;
            settings.UseSsl = useSsl;
            Assert.AreEqual(useSsl, settings.UseSsl);

            settings.Freeze();
            Assert.AreEqual(useSsl, settings.UseSsl);
            Assert.Throws<InvalidOperationException>(() => { settings.UseSsl = useSsl; });
        }
        public void TestServersWithTwoServers()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(_localHost, settings.Server);
            Assert.IsTrue(new[] { _localHost }.SequenceEqual(settings.Servers));

            var servers = new MongoServerAddress[]
            {
                new MongoServerAddress("server1"),
                new MongoServerAddress("server2")
            };
            settings.Servers = servers;
            Assert.Throws<InvalidOperationException>(() => { var s = settings.Server; });
            Assert.IsTrue(servers.SequenceEqual(settings.Servers));

            settings.Freeze();
            Assert.Throws<InvalidOperationException>(() => { var s = settings.Server; });
            Assert.IsTrue(servers.SequenceEqual(settings.Servers));
            Assert.Throws<InvalidOperationException>(() => { settings.Servers = servers; });
        }
        public void TestWriteConcern()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(WriteConcern.Acknowledged, settings.WriteConcern);

            var writeConcern = new WriteConcern();
            settings.WriteConcern = writeConcern;
            Assert.AreSame(writeConcern, settings.WriteConcern);

            settings.Freeze();
            Assert.AreEqual(writeConcern, settings.WriteConcern);
            Assert.Throws<InvalidOperationException>(() => { settings.WriteConcern = writeConcern; });
        }
        public void TestCredentialsStore()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual("{}", settings.CredentialsStore.ToString());

            var credentialsStore = new MongoCredentialsStore();
            settings.CredentialsStore = credentialsStore;
            Assert.AreSame(credentialsStore, settings.CredentialsStore);
            Assert.IsFalse(settings.CredentialsStore.IsFrozen);

            settings.Freeze();
            Assert.AreSame(credentialsStore, settings.CredentialsStore);
            Assert.IsTrue(settings.CredentialsStore.IsFrozen);
            Assert.Throws<InvalidOperationException>(() => { settings.CredentialsStore = credentialsStore; });
        }
        public void TestReadPreference()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(ReadPreference.Primary, settings.ReadPreference);

            var readPreference = new ReadPreference();
            settings.ReadPreference = readPreference;
            Assert.AreSame(readPreference, settings.ReadPreference);
            Assert.IsFalse(settings.ReadPreference.IsFrozen);

            settings.Freeze();
            Assert.AreEqual(readPreference, settings.ReadPreference);
            Assert.IsTrue(settings.ReadPreference.IsFrozen);
            Assert.Throws<InvalidOperationException>(() => { settings.ReadPreference = readPreference; });
        }
        public void TestMinConnectionPoolSize()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.MinConnectionPoolSize, settings.MinConnectionPoolSize);

            var minConnectionPoolSize = 123;
            settings.MinConnectionPoolSize = minConnectionPoolSize;
            Assert.AreEqual(minConnectionPoolSize, settings.MinConnectionPoolSize);

            settings.Freeze();
            Assert.AreEqual(minConnectionPoolSize, settings.MinConnectionPoolSize);
            Assert.Throws<InvalidOperationException>(() => { settings.MinConnectionPoolSize = minConnectionPoolSize; });
        }
        public void TestMaxConnectionLifeTime()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.MaxConnectionLifeTime, settings.MaxConnectionLifeTime);

            var maxConnectionLifeTime = new TimeSpan(1, 2, 3);
            settings.MaxConnectionLifeTime = maxConnectionLifeTime;
            Assert.AreEqual(maxConnectionLifeTime, settings.MaxConnectionLifeTime);

            settings.Freeze();
            Assert.AreEqual(maxConnectionLifeTime, settings.MaxConnectionLifeTime);
            Assert.Throws<InvalidOperationException>(() => { settings.MaxConnectionLifeTime = maxConnectionLifeTime; });
        }
        public void TestIPv6()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(false, settings.IPv6);

            var ipv6 = true;
            settings.IPv6 = ipv6;
            Assert.AreEqual(ipv6, settings.IPv6);

            settings.Freeze();
            Assert.AreEqual(ipv6, settings.IPv6);
            Assert.Throws<InvalidOperationException>(() => { settings.IPv6 = ipv6; });
        }
        public void TestGuidRepresentation()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.GuidRepresentation, settings.GuidRepresentation);

            var guidRepresentation = GuidRepresentation.PythonLegacy;
            settings.GuidRepresentation = guidRepresentation;
            Assert.AreEqual(guidRepresentation, settings.GuidRepresentation);

            settings.Freeze();
            Assert.AreEqual(guidRepresentation, settings.GuidRepresentation);
            Assert.Throws<InvalidOperationException>(() => { settings.GuidRepresentation = guidRepresentation; });
        }
        public void TestFreeze()
        {
            var settings = new MongoClientSettings();
            settings.ReadPreference = new ReadPreference();
            settings.WriteConcern = new WriteConcern();

            Assert.IsFalse(settings.IsFrozen);
            Assert.IsFalse(settings.CredentialsStore.IsFrozen);
            Assert.IsFalse(settings.ReadPreference.IsFrozen);
            Assert.IsFalse(settings.WriteConcern.IsFrozen);
            var hashCode = settings.GetHashCode();
            var stringRepresentation = settings.ToString();

            settings.Freeze();
            Assert.IsTrue(settings.IsFrozen);
            Assert.IsTrue(settings.CredentialsStore.IsFrozen);
            Assert.IsTrue(settings.ReadPreference.IsFrozen);
            Assert.IsTrue(settings.WriteConcern.IsFrozen);
            Assert.AreEqual(hashCode, settings.GetHashCode());
            Assert.AreEqual(stringRepresentation, settings.ToString());
        }
        public void TestSslSettings()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(null, settings.SslSettings);

            var sslSettings = new SslSettings { CheckCertificateRevocation = false };
            settings.SslSettings = sslSettings;
            Assert.AreEqual(sslSettings, settings.SslSettings);

            settings.Freeze();
            Assert.AreEqual(sslSettings, settings.SslSettings);
            Assert.Throws<InvalidOperationException>(() => { settings.SslSettings = sslSettings; });
        }
        public void TestWriteConcern()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(WriteConcern.Errors, settings.WriteConcern);

            var writeConcern = new WriteConcern();
            settings.WriteConcern = writeConcern;
            Assert.AreSame(writeConcern, settings.WriteConcern);
            Assert.IsFalse(settings.WriteConcern.IsFrozen);

            settings.Freeze();
            Assert.AreEqual(writeConcern, settings.WriteConcern);
            Assert.IsTrue(settings.WriteConcern.IsFrozen);
            Assert.Throws<InvalidOperationException>(() => { settings.WriteConcern = writeConcern; });
        }
        public void TestReplicaSetName()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(null, settings.ReplicaSetName);

            var replicaSetName = "abc";
            settings.ReplicaSetName = replicaSetName;
            Assert.AreSame(replicaSetName, settings.ReplicaSetName);

            settings.Freeze();
            Assert.AreSame(replicaSetName, settings.ReplicaSetName);
            Assert.Throws<InvalidOperationException>(() => { settings.ReplicaSetName = replicaSetName; });
        }
        public void TestSecondaryAcceptableLatency()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(MongoDefaults.SecondaryAcceptableLatency, settings.SecondaryAcceptableLatency);

            var secondaryAcceptableLatency = new TimeSpan(1, 2, 3);
            settings.SecondaryAcceptableLatency = secondaryAcceptableLatency;
            Assert.AreEqual(secondaryAcceptableLatency, settings.SecondaryAcceptableLatency);

            settings.Freeze();
            Assert.AreEqual(secondaryAcceptableLatency, settings.SecondaryAcceptableLatency);
            Assert.Throws<InvalidOperationException>(() => { settings.SecondaryAcceptableLatency = secondaryAcceptableLatency; });
        }
        public void TestDefaultCredentials()
        {
            var settings = new MongoClientSettings();
            Assert.AreEqual(null, settings.DefaultCredentials);

            var defaultCredentials = new MongoCredentials("user1", "password1");
            settings.DefaultCredentials = defaultCredentials;
            Assert.AreSame(defaultCredentials, settings.DefaultCredentials);

            settings.Freeze();
            Assert.AreSame(defaultCredentials, settings.DefaultCredentials);
            Assert.Throws<InvalidOperationException>(() => { settings.DefaultCredentials = defaultCredentials; });
        }
        public void TestFreeze()
        {
            var settings = new MongoClientSettings();

            Assert.IsFalse(settings.IsFrozen);
            var hashCode = settings.GetHashCode();
            var stringRepresentation = settings.ToString();

            settings.Freeze();
            Assert.IsTrue(settings.IsFrozen);
            Assert.AreEqual(hashCode, settings.GetHashCode());
            Assert.AreEqual(stringRepresentation, settings.ToString());
        }