public void GetEnumerator_ChangeWhileEnumerating_GetsOriginalList()
        {
            // Arrange

            var node1 = CreateMockNode(CreateEndpoint(1)).Object;
            var node2 = CreateMockNode(CreateEndpoint(2)).Object;

            var nodes = new ClusterNodeCollection
            {
                node1,
                node2
            };

            Assert.Equal(2, nodes.Count);

            // Act

            using var enumerator = nodes.GetEnumerator();
            Assert.True(enumerator.MoveNext());

            Assert.True(nodes.Remove(CreateEndpoint(1), out _));

            // Assert

            Assert.True(enumerator.MoveNext());
            Assert.False(enumerator.MoveNext());
        }
        public void Remove_NotInCollection_ReturnsFalse()
        {
            // Arrange

            var nodes = new ClusterNodeCollection();

            // Act

            var result = nodes.Remove(CreateEndpoint(1), out _);

            // Assert

            Assert.False(result);
        }
        public void Remove_InCollection_UnregistersForEvents()
        {
            // Arrange

            var node = CreateMockNode(CreateEndpoint(1));

            var nodes = new ClusterNodeCollection
            {
                node.Object
            };

            // Act

            nodes.Remove(CreateEndpoint(1), out _);

            // Assert

            node.VerifyRemove(m => m.KeyEndPointsChanged -= It.IsAny <NotifyCollectionChangedEventHandler>(), Times.AtLeastOnce);
        }
        public void Remove_InCollection_UnregistersAllEndpoints()
        {
            // Arrange

            var node = CreateMockNode(CreateEndpoint(1), CreateEndpoint(2)).Object;

            var nodes = new ClusterNodeCollection()
            {
                node
            };

            // Act

            nodes.Remove(CreateEndpoint(1), out _);

            // Assert

            Assert.False(nodes.TryGet(CreateEndpoint(1), out _));
            Assert.False(nodes.TryGet(CreateEndpoint(2), out _));
        }
        public void Remove_InCollection_ReturnsTrue()
        {
            // Arrange

            var node = CreateMockNode(CreateEndpoint(1)).Object;

            var nodes = new ClusterNodeCollection
            {
                node
            };

            // Act

            var result = nodes.Remove(CreateEndpoint(1), out var removedNode);

            // Assert

            Assert.True(result);
            Assert.Equal(node, removedNode);
        }
        public void Remove_InCollection_ReducesCount()
        {
            // Arrange

            var node = CreateMockNode(CreateEndpoint(1)).Object;

            var nodes = new ClusterNodeCollection
            {
                node
            };

            Assert.Equal(1, nodes.Count);

            // Act

            var result = nodes.Remove(CreateEndpoint(1), out _);

            // Assert

            Assert.Equal(0, nodes.Count);
        }