public void TestMaxCapacity() { LimitedNodeAddressDictionary dict = new LimitedNodeAddressDictionary(3, TimeSpan.FromMinutes(10)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.1"), 8001)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.2"), 8002)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.4"), 8004)); Assert.That(dict.GetOldest(2), Is.EqualTo(new List<NodeAddress> { new NodeAddress(IPAddress.Parse("192.168.0.2"), 8002), new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003) })); Assert.That(dict.GetNewest(2), Is.EqualTo(new List<NodeAddress> { new NodeAddress(IPAddress.Parse("192.168.0.4"), 8004), new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003) })); Assert.That(dict.GetOldest(5), Is.EqualTo(new List<NodeAddress> { new NodeAddress(IPAddress.Parse("192.168.0.2"), 8002), new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003), new NodeAddress(IPAddress.Parse("192.168.0.4"), 8004) })); Assert.That(dict.GetNewest(5), Is.EqualTo(new List<NodeAddress> { new NodeAddress(IPAddress.Parse("192.168.0.4"), 8004), new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003), new NodeAddress(IPAddress.Parse("192.168.0.2"), 8002) })); Assert.False(dict.ContainsKey(new NodeAddress(IPAddress.Parse("192.168.0.1"), 8001))); Assert.True(dict.ContainsKey(new NodeAddress(IPAddress.Parse("192.168.0.2"), 8002))); Assert.True(dict.ContainsKey(new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003))); Assert.True(dict.ContainsKey(new NodeAddress(IPAddress.Parse("192.168.0.4"), 8004))); Assert.False(dict.ContainsKey(new NodeAddress(IPAddress.Parse("192.168.0.5"), 8005))); }
public void TestGetNegativeCount() { LimitedNodeAddressDictionary dict = new LimitedNodeAddressDictionary(3, TimeSpan.FromMinutes(10)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.1"), 8001)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.2"), 8002)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.3"), 8003)); dict.Add(new NodeAddress(IPAddress.Parse("192.168.0.4"), 8004)); Assert.That(dict.GetOldest(-1), Is.EqualTo(new List<NodeAddress>())); Assert.That(dict.GetNewest(-1), Is.EqualTo(new List<NodeAddress>())); }