示例#1
0
        public void ToClusterKey_should_copy_relevant_values()
        {
            var credentials = new[] { MongoCredential.CreateMongoCRCredential("source", "username", "password") };
            var servers     = new[] { new MongoServerAddress("localhost") };
            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Tls
            };

            var subject = new MongoServerSettings
            {
                ApplicationName    = "app",
                ConnectionMode     = ConnectionMode.Direct,
                ConnectTimeout     = TimeSpan.FromSeconds(1),
                Credentials        = credentials,
                GuidRepresentation = GuidRepresentation.Standard,
                HeartbeatInterval  = TimeSpan.FromMinutes(1),
                HeartbeatTimeout   = TimeSpan.FromMinutes(2),
                IPv6 = true,
                MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize = 10,
                MinConnectionPoolSize = 5,
                ReplicaSetName        = "rs",
                LocalThreshold        = TimeSpan.FromMilliseconds(20),
                Servers = servers,
                ServerSelectionTimeout = TimeSpan.FromSeconds(6),
                SocketTimeout          = TimeSpan.FromSeconds(4),
                SslSettings            = sslSettings,
                UseSsl = true,
                VerifySslCertificate = true,
                WaitQueueSize        = 20,
                WaitQueueTimeout     = TimeSpan.FromSeconds(5)
            };

            var result = subject.ToClusterKey();

            result.ApplicationName.Should().Be(subject.ApplicationName);
            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.ConnectTimeout.Should().Be(subject.ConnectTimeout);
            result.Credentials.Should().Equal(subject.Credentials);
            result.HeartbeatInterval.Should().Be(subject.HeartbeatInterval);
            result.HeartbeatTimeout.Should().Be(subject.HeartbeatTimeout);
            result.IPv6.Should().Be(subject.IPv6);
            result.MaxConnectionIdleTime.Should().Be(subject.MaxConnectionIdleTime);
            result.MaxConnectionLifeTime.Should().Be(subject.MaxConnectionLifeTime);
            result.MaxConnectionPoolSize.Should().Be(subject.MaxConnectionPoolSize);
            result.MinConnectionPoolSize.Should().Be(subject.MinConnectionPoolSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.Servers.Should().Equal(subject.Servers);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
            result.SocketTimeout.Should().Be(subject.SocketTimeout);
            result.SslSettings.Should().Be(subject.SslSettings);
            result.UseSsl.Should().Be(subject.UseSsl);
            result.VerifySslCertificate.Should().Be(subject.VerifySslCertificate);
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }
示例#2
0
        public void ToClusterKey_should_copy_relevant_values()
        {
            var clusterConfigurator = new Action <ClusterBuilder>(b => { });

#pragma warning disable 618
            var credential = MongoCredential.CreateMongoCRCredential("source", "username", "password");
#pragma warning restore 618
            var servers     = new[] { new MongoServerAddress("localhost") };
            var sslSettings = new SslSettings
            {
                CheckCertificateRevocation = true,
                EnabledSslProtocols        = SslProtocols.Tls
            };

            var subject = new MongoServerSettings
            {
                AllowInsecureTls    = false,
                ApplicationName     = "app",
                ClusterConfigurator = clusterConfigurator,
                ConnectionMode      = ConnectionMode.Direct,
                ConnectTimeout      = TimeSpan.FromSeconds(1),
                Credential          = credential,
                HeartbeatInterval   = TimeSpan.FromMinutes(1),
                HeartbeatTimeout    = TimeSpan.FromMinutes(2),
                IPv6                   = true,
                LocalThreshold         = TimeSpan.FromMilliseconds(20),
                MaxConnectionIdleTime  = TimeSpan.FromSeconds(2),
                MaxConnectionLifeTime  = TimeSpan.FromSeconds(3),
                MaxConnectionPoolSize  = 10,
                MinConnectionPoolSize  = 5,
                ReplicaSetName         = "rs",
                Scheme                 = ConnectionStringScheme.MongoDBPlusSrv,
                SdamLogFilename        = "navi",
                Servers                = servers,
                ServerSelectionTimeout = TimeSpan.FromSeconds(6),
                SocketTimeout          = TimeSpan.FromSeconds(4),
                SslSettings            = sslSettings,
                UseTls                 = true,
#pragma warning disable 618
                WaitQueueSize = 20,
#pragma warning restore 618
                WaitQueueTimeout = TimeSpan.FromSeconds(5)
            };
#pragma warning disable 618
            if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2)
            {
                subject.GuidRepresentation = GuidRepresentation.Standard;
            }
#pragma warning restore 618

            var result = subject.ToClusterKey();

            result.AllowInsecureTls.Should().Be(subject.AllowInsecureTls);
            result.ApplicationName.Should().Be(subject.ApplicationName);
            result.ClusterConfigurator.Should().BeSameAs(subject.ClusterConfigurator);
            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.ConnectTimeout.Should().Be(subject.ConnectTimeout);
#pragma warning disable 618
            result.Credentials.Should().Equal(subject.Credentials);
#pragma warning restore
            result.HeartbeatInterval.Should().Be(subject.HeartbeatInterval);
            result.HeartbeatTimeout.Should().Be(subject.HeartbeatTimeout);
            result.IPv6.Should().Be(subject.IPv6);
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.MaxConnectionIdleTime.Should().Be(subject.MaxConnectionIdleTime);
            result.MaxConnectionLifeTime.Should().Be(subject.MaxConnectionLifeTime);
            result.MaxConnectionPoolSize.Should().Be(subject.MaxConnectionPoolSize);
            result.MinConnectionPoolSize.Should().Be(subject.MinConnectionPoolSize);
            result.ReceiveBufferSize.Should().Be(MongoDefaults.TcpReceiveBufferSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(subject.Scheme);
            result.SdamLogFilename.Should().Be(subject.SdamLogFilename);
            result.SendBufferSize.Should().Be(MongoDefaults.TcpSendBufferSize);
            result.Servers.Should().Equal(subject.Servers);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
            result.SocketTimeout.Should().Be(subject.SocketTimeout);
            result.SslSettings.Should().Be(subject.SslSettings);
            result.UseTls.Should().Be(subject.UseTls);
#pragma warning disable 618
            result.WaitQueueSize.Should().Be(subject.WaitQueueSize);
#pragma warning restore 618
            result.WaitQueueTimeout.Should().Be(subject.WaitQueueTimeout);
        }