public void With_valid_srvMaxHosts_should_return_expected_result([Values(0, 42)] int srvMaxHosts)
        {
            var subject = new ClusterSettings(srvMaxHosts: 5);

            var result = subject.With(srvMaxHosts: srvMaxHosts);

            result.SrvMaxHosts.Should().Be(srvMaxHosts);
        }
        public void With_negative_srvMaxHosts_should_throw()
        {
            var subject = new ClusterSettings();

            var exception = Record.Exception(() => subject.With(srvMaxHosts: -1));

            exception.Should().BeOfType <ArgumentOutOfRangeException>()
            .Subject.ParamName.Should().Be("srvMaxHosts");
        }
        public void With_endPoints_should_return_expected_result()
        {
            var oldEndPoints = new[] { new DnsEndPoint("remotehost1", 27123) };
            var newEndPoints = new[] { new DnsEndPoint("remotehost2", 27123) };
            var subject      = new ClusterSettings(endPoints: oldEndPoints);

            var result = subject.With(endPoints: newEndPoints);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(newEndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
        public void With_replicaSetName_should_return_expected_result()
        {
            var oldReplicaSetName = "abc";
            var newReplicaSetName = "def";
            var subject           = new ClusterSettings(replicaSetName: oldReplicaSetName);

            var result = subject.With(replicaSetName: newReplicaSetName);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(newReplicaSetName);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
        public void With_serverSelectionTimeout_should_return_expected_result()
        {
            var oldServerSelectionTimeout = TimeSpan.FromSeconds(1);
            var newServerSelectionTimeout = TimeSpan.FromSeconds(2);
            var subject = new ClusterSettings(serverSelectionTimeout: oldServerSelectionTimeout);

            var result = subject.With(serverSelectionTimeout: newServerSelectionTimeout);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.ServerSelectionTimeout.Should().Be(newServerSelectionTimeout);
        }
Exemple #6
0
        public void With_scheme_should_return_expected_result()
        {
            var oldScheme = ConnectionStringScheme.MongoDB;
            var newScheme = ConnectionStringScheme.MongoDBPlusSrv;
            var subject   = new ClusterSettings(scheme: oldScheme);

            var result = subject.With(scheme: newScheme);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(newScheme);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
Exemple #7
0
        public void With_connectionMode_should_return_expected_result()
        {
            var oldConnectionMode = ClusterConnectionMode.Automatic;
            var newConnectionMode = ClusterConnectionMode.ReplicaSet;
            var subject           = new ClusterSettings(connectionMode: oldConnectionMode);

            var result = subject.With(connectionMode: newConnectionMode);

            result.ConnectionMode.Should().Be(newConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(subject.Scheme);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
Exemple #8
0
        public void With_maxServerSelectionWaitQueueSize_should_return_expected_result()
        {
            var oldMaxServerSelectionWaitQueueSize = 1;
            var newMaxServerSelectionWaitQueueSize = 2;
            var subject = new ClusterSettings(maxServerSelectionWaitQueueSize: oldMaxServerSelectionWaitQueueSize);

            var result = subject.With(maxServerSelectionWaitQueueSize: newMaxServerSelectionWaitQueueSize);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.MaxServerSelectionWaitQueueSize.Should().Be(newMaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(subject.Scheme);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
        public void With_serverSelectionTimeout_should_return_expected_result()
        {
            var oldServerSelectionTimeout = TimeSpan.FromSeconds(1);
            var newServerSelectionTimeout = TimeSpan.FromSeconds(2);
            var subject = new ClusterSettings(serverSelectionTimeout: oldServerSelectionTimeout);

            var result = subject.With(serverSelectionTimeout: newServerSelectionTimeout);

#pragma warning disable CS0618 // Type or member is obsolete
            result.ConnectionMode.Should().Be(subject.ConnectionMode);
#pragma warning restore CS0618 // Type or member is obsolete
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(subject.Scheme);
            result.ServerSelectionTimeout.Should().Be(newServerSelectionTimeout);
        }
        public void With_endPoints_should_return_expected_result()
        {
            var oldEndPoints = new[] { new DnsEndPoint("remotehost1", 27123) };
            var newEndPoints = new[] { new DnsEndPoint("remotehost2", 27123) };
            var subject      = new ClusterSettings(endPoints: oldEndPoints);

            var result = subject.With(endPoints: newEndPoints);

#pragma warning disable CS0618 // Type or member is obsolete
            result.ConnectionMode.Should().Be(subject.ConnectionMode);
#pragma warning restore CS0618 // Type or member is obsolete
            result.EndPoints.Should().EqualUsing(newEndPoints, EndPointHelper.EndPointEqualityComparer);
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(subject.Scheme);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
        public void With_scheme_should_return_expected_result()
        {
            var oldScheme = ConnectionStringScheme.MongoDB;
            var newScheme = ConnectionStringScheme.MongoDBPlusSrv;
            var subject   = new ClusterSettings(scheme: oldScheme);

            var result = subject.With(scheme: newScheme);

#pragma warning disable CS0618 // Type or member is obsolete
            result.ConnectionMode.Should().Be(subject.ConnectionMode);
#pragma warning restore CS0618 // Type or member is obsolete
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.LoadBalanced.Should().BeFalse();
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(newScheme);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
        public void With_connectionMode_should_return_expected_result()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var oldConnectionMode = ClusterConnectionMode.Automatic;
            var newConnectionMode = ClusterConnectionMode.ReplicaSet;
            var subject           = new ClusterSettings(connectionModeSwitch: ConnectionModeSwitch.UseConnectionMode, connectionMode: oldConnectionMode);
#pragma warning restore CS0618 // Type or member is obsolete

            var result = subject.With(connectionMode: newConnectionMode);

#pragma warning disable CS0618 // Type or member is obsolete
            result.ConnectionMode.Should().Be(newConnectionMode);
#pragma warning restore CS0618 // Type or member is obsolete
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.LocalThreshold.Should().Be(subject.LocalThreshold);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.Scheme.Should().Be(subject.Scheme);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
        public void With_serverSelectionTimeout_should_return_expected_result()
        {
            var oldServerSelectionTimeout = TimeSpan.FromSeconds(1);
            var newServerSelectionTimeout = TimeSpan.FromSeconds(2);
            var subject = new ClusterSettings(serverSelectionTimeout: oldServerSelectionTimeout);

            var result = subject.With(serverSelectionTimeout: newServerSelectionTimeout);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.ServerSelectionTimeout.Should().Be(newServerSelectionTimeout);
        }
        public void With_endPoints_should_return_expected_result()
        {
            var oldEndPoints = new[] { new DnsEndPoint("remotehost1", 27123) };
            var newEndPoints = new[] { new DnsEndPoint("remotehost2", 27123) };
            var subject = new ClusterSettings(endPoints: oldEndPoints);

            var result = subject.With(endPoints: newEndPoints);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(newEndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(subject.ReplicaSetName);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
 private ClusterSettings ConfigureCluster(ClusterSettings settings, ClusterKey clusterKey)
 {
     var endPoints = clusterKey.Servers.Select(s => EndPointHelper.Parse(s.ToString()));
     return settings.With(
         connectionMode: clusterKey.ConnectionMode.ToCore(),
         endPoints: Optional.Enumerable(endPoints),
         replicaSetName: clusterKey.ReplicaSetName,
         maxServerSelectionWaitQueueSize: clusterKey.WaitQueueSize,
         serverSelectionTimeout: clusterKey.ServerSelectionTimeout,
         postServerSelector: new LatencyLimitingServerSelector(clusterKey.LocalThreshold));
 }
        public void With_replicaSetName_should_return_expected_result()
        {
            var oldReplicaSetName = "abc";
            var newReplicaSetName = "def";
            var subject = new ClusterSettings(replicaSetName: oldReplicaSetName);

            var result = subject.With(replicaSetName: newReplicaSetName);

            result.ConnectionMode.Should().Be(subject.ConnectionMode);
            result.EndPoints.Should().EqualUsing(subject.EndPoints, EndPointHelper.EndPointEqualityComparer);
            result.MaxServerSelectionWaitQueueSize.Should().Be(subject.MaxServerSelectionWaitQueueSize);
            result.ReplicaSetName.Should().Be(newReplicaSetName);
            result.ServerSelectionTimeout.Should().Be(subject.ServerSelectionTimeout);
        }
Exemple #17
0
        private StubCluster CreateSubject(ClusterConnectionMode connectionMode = ClusterConnectionMode.Automatic, TimeSpan? serverSelectionTimeout = null)
        {
            _settings = _settings.With(connectionMode: connectionMode);
            if (serverSelectionTimeout != null)
            {
                _settings = _settings.With(serverSelectionTimeout: serverSelectionTimeout.Value);
            }

            return new StubCluster(_settings, _mockServerFactory.Object, _capturedEvents);
        }