public void TestServer() { var settings = new MongoServerSettings(); Assert.AreEqual(_localHost, settings.Server); Assert.IsTrue(new[] { _localHost }.SequenceEqual(settings.Servers)); var server = new MongoServerAddress("server"); var servers = new[] { server }; settings.Server = server; Assert.AreEqual(server, settings.Server); Assert.IsTrue(servers.SequenceEqual(settings.Servers)); settings.Freeze(); Assert.AreEqual(server, settings.Server); Assert.IsTrue(servers.SequenceEqual(settings.Servers)); Assert.Throws <InvalidOperationException>(() => { settings.Server = server; }); }
public void TestFreeze() { var settings = new MongoServerSettings(); settings.ReadPreference = new ReadPreference(); settings.WriteConcern = new WriteConcern(); Assert.IsFalse(settings.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.ReadPreference.IsFrozen); Assert.IsTrue(settings.WriteConcern.IsFrozen); Assert.AreEqual(hashCode, settings.GetHashCode()); Assert.AreEqual(stringRepresentation, settings.ToString()); }
public void TestServersWithTwoServers() { var settings = new MongoServerSettings(); Assert.Equal(_localHost, settings.Server); Assert.True(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.True(servers.SequenceEqual(settings.Servers)); settings.Freeze(); Assert.Throws <InvalidOperationException>(() => { var s = settings.Server; }); Assert.True(servers.SequenceEqual(settings.Servers)); Assert.Throws <InvalidOperationException>(() => { settings.Servers = servers; }); }
public void TestDefaults() { var localhost = new MongoServerAddress("localhost"); var settings = new MongoServerSettings(); Assert.AreEqual(ConnectionMode.Direct, settings.ConnectionMode); Assert.AreEqual(MongoDefaults.ConnectTimeout, settings.ConnectTimeout); Assert.AreEqual(null, settings.DefaultCredentials); Assert.AreEqual(MongoDefaults.GuidRepresentation, settings.GuidRepresentation); Assert.AreEqual(false, settings.IPv6); 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(ReadPreference.Primary, settings.ReadPreference); Assert.AreEqual(null, settings.ReplicaSetName); Assert.AreEqual(SafeMode.False, settings.SafeMode); Assert.AreEqual(1, settings.Servers.Count()); Assert.AreEqual(localhost, settings.Server); Assert.AreEqual(localhost, settings.Servers.First()); Assert.AreEqual(MongoDefaults.SocketTimeout, settings.SocketTimeout); Assert.AreEqual(false, settings.UseSsl); 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()); }