Example #1
0
        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"));
        }
Example #2
0
        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"));
        }
Example #3
0
        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"));
        }
Example #4
0
        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"));
        }
Example #5
0
        public virtual void TestGetCollection()
        {
            //create MachineList with a mix of ip addresses , hostnames and ip ranges
            MachineList          ml  = new MachineList(HostnameIpCidrList);
            ICollection <string> col = ml.GetCollection();

            //test getCollectionton to return the full collection
            Assert.Equal(7, ml.GetCollection().Count);
            foreach (string item in StringUtils.GetTrimmedStringCollection(HostnameIpCidrList
                                                                           ))
            {
                Assert.True(col.Contains(item));
            }
        }
Example #6
0
        public virtual void TestCIDRWith8BitMask()
        {
            //create MachineList with a list of of ip ranges specified in CIDR format
            MachineList ml = new MachineList(CidrList2);

            //test for inclusion/exclusion
            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.1"));
            Assert.True(ml.Includes("10.241.23.254"));
            Assert.True(ml.Includes("10.241.23.255"));
            NUnit.Framework.Assert.IsFalse(ml.Includes("10.241.24.0"));
            //test for exclusion with an unknown IP
            NUnit.Framework.Assert.IsFalse(ml.Includes("10.119.103.111"));
        }
Example #7
0
        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"));
        }
Example #8
0
 public FileBasedIPList(string fileName)
 {
     this.fileName = fileName;
     string[] lines;
     try
     {
         lines = ReadLines(fileName);
     }
     catch (IOException)
     {
         lines = null;
     }
     if (lines != null)
     {
         addressList = new MachineList(new HashSet <string>(Arrays.AsList(lines)));
     }
     else
     {
         addressList = null;
     }
 }