public void AddTest() { var list = new IPList(IPListLookupPriority.IndividualIP); list.Add("192.168.1.1", "rule1"); list.Add("192.168.1.2", null); list.Add(IPHelper.ParseIP("192.168.1.3"), "rule3"); list.Add(IPHelper.ParseIP("192.168.1.4"), null); list.Prepare(); Assert.IsTrue(list.Check("192.168.1.1")); Assert.IsTrue(list.Check("192.168.1.2")); Assert.IsTrue(list.Check("192.168.1.3")); Assert.IsTrue(list.Check("192.168.1.4")); Assert.IsFalse(list.Check("192.168.1.100")); object rule; Assert.IsTrue(list.TryGetRule("192.168.1.1", out rule)); Assert.AreEqual("rule1", (string)rule); Assert.IsTrue(list.TryGetRule("192.168.1.2", out rule)); Assert.IsNull(rule); Assert.IsTrue(list.TryGetRule("192.168.1.3", out rule)); Assert.AreEqual("rule3", (string)rule); Assert.IsTrue(list.TryGetRule("192.168.1.4", out rule)); Assert.IsNull(rule); Assert.IsFalse(list.TryGetRule("192.168.1.100", out rule)); Assert.IsNull(rule); }
public void AddRangeTest() { var list = new IPList(IPListLookupPriority.IndividualIP); list.Add("192.168.1.0", 24, "rule1"); list.Prepare(); Assert.IsTrue(list.Check("192.168.1.0")); Assert.IsTrue(list.Check("192.168.1.100")); Assert.IsTrue(list.Check("192.168.1.255")); Assert.IsFalse(list.Check("192.168.2.0")); object rule; Assert.IsTrue(list.TryGetRule("192.168.1.0", out rule)); Assert.AreEqual("rule1", (string)rule); Assert.IsTrue(list.TryGetRule("192.168.1.100", out rule)); Assert.AreEqual("rule1", (string)rule); Assert.IsTrue(list.TryGetRule("192.168.1.255", out rule)); Assert.AreEqual("rule1", (string)rule); Assert.IsFalse(list.TryGetRule("192.168.2.0", out rule)); Assert.IsNull(rule); }
public void LookupPriorityTest() { var list1 = new IPList(IPListLookupPriority.IndividualIP); list1.Add("192.168.1.0", "rule1"); list1.Add("192.168.1.0", 24, "rule2"); list1.Prepare(); var list2 = new IPList(IPListLookupPriority.IPRange); list2.Add("192.168.1.0", "rule1"); list2.Add("192.168.1.0", 24, "rule2"); list2.Prepare(); object rule; Assert.IsTrue(list1.TryGetRule("192.168.1.0", out rule)); Assert.AreEqual("rule1", (string)rule); Assert.IsTrue(list2.TryGetRule("192.168.1.0", out rule)); Assert.AreEqual("rule2", (string)rule); }