public virtual void TestHostNames() { //create MachineList with a list of of Hostnames IPAddress addressHost1 = Extensions.GetAddressByName("1.2.3.1"); IPAddress addressHost4 = Extensions.GetAddressByName("1.2.3.4"); IPAddress addressMockHost4 = Org.Mockito.Mockito.Mock <IPAddress>(); Org.Mockito.Mockito.When(addressMockHost4.ToString()).ThenReturn("differentName"); IPAddress addressMockHost5 = Org.Mockito.Mockito.Mock <IPAddress>(); Org.Mockito.Mockito.When(addressMockHost5.ToString()).ThenReturn("host5"); MachineList.InetAddressFactory addressFactory = Org.Mockito.Mockito.Mock <MachineList.InetAddressFactory >(); Org.Mockito.Mockito.When(addressFactory.GetByName("1.2.3.4")).ThenReturn(addressMockHost4 ); Org.Mockito.Mockito.When(addressFactory.GetByName("1.2.3.5")).ThenReturn(addressMockHost5 ); Org.Mockito.Mockito.When(addressFactory.GetByName("host1")).ThenReturn(addressHost1 ); Org.Mockito.Mockito.When(addressFactory.GetByName("host4")).ThenReturn(addressHost4 ); MachineList ml = new MachineList(StringUtils.GetTrimmedStringCollection(HostList) , addressFactory); //test for inclusion with an known IP Assert.True(ml.Includes("1.2.3.4")); //test for exclusion with an unknown IP NUnit.Framework.Assert.IsFalse(ml.Includes("1.2.3.5")); }
public virtual void TestWildCard() { //create MachineList with a list of of IPs MachineList ml = new MachineList("*"); //test for inclusion with any IP Assert.True(ml.Includes("10.119.103.112")); Assert.True(ml.Includes("1.2.3.4")); }
public virtual void TestIPListSpaces() { //create MachineList with a ip string which has duplicate ip and spaces MachineList ml = new MachineList(IpListSpaces); //test for inclusion with an known IP Assert.True(ml.Includes("10.119.103.112")); //test for exclusion with an unknown IP NUnit.Framework.Assert.IsFalse(ml.Includes("10.119.103.111")); }
public virtual void TestIPList() { //create MachineList with a list of of IPs MachineList ml = new MachineList(IpList); //test for inclusion with an known IP Assert.True(ml.Includes("10.119.103.112")); //test for exclusion with an unknown IP NUnit.Framework.Assert.IsFalse(ml.Includes("10.119.103.111")); }
public virtual bool IsIn(string ipAddress) { if (ipAddress == null || addressList == null) { return(false); } return(addressList.Includes(ipAddress)); }
public virtual void TestHostNameIPandCIDRs() { //create MachineList with a mix of ip addresses , hostnames and ip ranges MachineList ml = new MachineList(HostnameIpCidrList); //test for inclusion with an known IP Assert.True(ml.Includes("10.119.103.112")); //test for exclusion with an unknown IP NUnit.Framework.Assert.IsFalse(ml.Includes("10.119.103.111")); //CIDR Ranges NUnit.Framework.Assert.IsFalse(ml.Includes("10.221.255.255")); Assert.True(ml.Includes("10.222.0.0")); Assert.True(ml.Includes("10.222.255.255")); NUnit.Framework.Assert.IsFalse(ml.Includes("10.223.0.0")); NUnit.Framework.Assert.IsFalse(ml.Includes("10.241.22.255")); Assert.True(ml.Includes("10.241.23.0")); Assert.True(ml.Includes("10.241.23.255")); NUnit.Framework.Assert.IsFalse(ml.Includes("10.241.24.0")); }
public virtual void TestCIDRWith16bitmask() { //create MachineList with a list of of ip ranges specified in CIDR format MachineList ml = new MachineList(CidrList1); //test for inclusion/exclusion NUnit.Framework.Assert.IsFalse(ml.Includes("10.221.255.255")); Assert.True(ml.Includes("10.222.0.0")); Assert.True(ml.Includes("10.222.0.1")); Assert.True(ml.Includes("10.222.0.255")); Assert.True(ml.Includes("10.222.255.0")); Assert.True(ml.Includes("10.222.255.254")); Assert.True(ml.Includes("10.222.255.255")); NUnit.Framework.Assert.IsFalse(ml.Includes("10.223.0.0")); //test for exclusion with an unknown IP NUnit.Framework.Assert.IsFalse(ml.Includes("10.119.103.111")); }