public void Should_invalidate_existing_primary_when_a_new_primary_shows_up_and_current_set_version_and_election_id_are_null() { _settings = _settings.With(endPoints: new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }); var subject = CreateSubject(); subject.Initialize(); _capturedEvents.Clear(); PublishDescription(subject, _firstEndPoint, ServerType.ReplicaSetPrimary); PublishDescription(subject, _secondEndPoint, ServerType.ReplicaSetPrimary); var description = subject.Description; description.Servers.Should().BeEquivalentToWithComparer( new[] { GetDisconnectedDescription(_firstEndPoint) }.Concat(GetDescriptions(_secondEndPoint, _thirdEndPoint)), _serverDescriptionComparer); var mockServer = Mock.Get(_serverFactory.GetServer(_firstEndPoint)); mockServer.Verify(s => s.Invalidate(), Times.Once); _capturedEvents.Next().Should().BeOfType <ClusterDescriptionChangedEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterDescriptionChangedEvent>(); _capturedEvents.Any().Should().BeFalse(); }
public void Initialize_should_create_and_initialize_the_server() { var subject = CreateSubject(); subject.Initialize(); _serverFactory.GetServer(_endPoint).Received().Initialize(); _capturedEvents.Next().Should().BeOfType <ClusterOpeningEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterAddingServerEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterAddedServerEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterOpenedEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterDescriptionChangedEvent>(); _capturedEvents.Any().Should().BeFalse(); }
public void Initialize_should_create_and_initialize_the_server() { var subject = CreateSubject(); subject.Initialize(); var mockServer = Mock.Get(_mockServerFactory.GetServer(_endPoint)); mockServer.Verify(s => s.Initialize(), Times.Once); _capturedEvents.Next().Should().BeOfType <ClusterOpeningEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterAddingServerEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterAddedServerEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterDescriptionChangedEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterOpenedEvent>(); _capturedEvents.Any().Should().BeFalse(); }
public void Should_call_initialize_on_all_servers() { _settings = _settings.WithEndPoints(new[] { _firstEndPoint, _secondEndPoint }); var subject = CreateSubject(); subject.Initialize(); PublishDescription(_firstEndPoint, ServerType.ReplicaSetPrimary, hosts: new[] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }); foreach (var endPoint in new [] { _firstEndPoint, _secondEndPoint, _thirdEndPoint }) { var server = _serverFactory.GetServer(endPoint); server.Received().Initialize(); } }
public void Dispose_should_dispose_of_the_server() { var subject = CreateSubject(); subject._state().Value.Should().Be(0); // initial subject.Initialize(); subject._state().Value.Should().Be(1); // opened _capturedEvents.Clear(); subject.Dispose(); subject._state().Value.Should().Be(2); // disposed var mockServer = Mock.Get(_mockServerFactory.GetServer(_endPoint)); mockServer.Verify(s => s.Dispose(), Times.Once); _capturedEvents.Next().Should().BeOfType <ClusterClosingEvent>(); _capturedEvents.Next().Should().BeOfType <ClusterClosedEvent>(); _capturedEvents.Any().Should().BeFalse(); }