public void RemoveKeyEndPoint_RemovesFromLookup()
        {
            // Arrange

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

            var nodes = new ClusterNodeCollection
            {
                node.Object
            };

            var args = new NotifyCollectionChangedEventArgs(
                NotifyCollectionChangedAction.Remove,
                new List <HostEndpointWithPort> {
                CreateEndpoint(2)
            },
                1);

            // Act

            node.Raise(m => m.KeyEndPointsChanged += null, args);

            // Assert

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

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

            var nodes = new ClusterNodeCollection();

            // Act

            nodes.Add(node);

            // Assert

            Assert.True(nodes.TryGet(CreateEndpoint(1), out var resultNode));
            Assert.Equal(node, resultNode);

            Assert.True(nodes.TryGet(CreateEndpoint(2), out resultNode));
            Assert.Equal(node, resultNode);
        }
        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 Clear_RemovesFromLookup()
        {
            // 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

            nodes.Clear();

            // Assert

            Assert.False(nodes.TryGet(CreateEndpoint(1), out _));
            Assert.False(nodes.TryGet(CreateEndpoint(2), out _));
        }