示例#1
0
        public void A()
        {
            var a = Cidr.Parse("92.223.124.5/32");

            Assert.Equal(IPAddress.Parse("92.223.124.5"), a.Start);
            Assert.Equal(IPAddress.Parse("92.223.124.5"), a.End);
        }
示例#2
0
        public void Cidr_Parse_Parses_Addresses_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            // Uncomment this block if you want to restrict the test to just those rows with a RunThis of true
            // var runThis = worksheet.NBool("RunThis").GetValueOrDefault();
            // if(!runThis) Assert.Fail();

            var       address   = worksheet.EString("Parse");
            Exception exception = null;
            Cidr      cidr      = null;

            try {
                cidr = Cidr.Parse(address);
            } catch (Exception ex) {
                exception = ex;
            }

            Assert.AreEqual(exception != null, worksheet.NBool("Exception").GetValueOrDefault(), exception == null ? "Did not see exception" : exception.Message);
            if (exception == null)
            {
                Assert.AreEqual(GetExcelIPAddress(worksheet, "Address"), cidr.Address);
                Assert.AreEqual(GetExcelIPAddress(worksheet, "MaskedAddress"), cidr.MaskedAddress);
                Assert.AreEqual(worksheet.Int("BitmaskBits"), cidr.BitmaskBits);
                Assert.AreEqual(worksheet.UInt("IPv4Bitmask"), cidr.IPv4Bitmask);
                Assert.AreEqual(GetExcelIPAddress(worksheet, "From"), cidr.FirstMatchingAddress);
                Assert.AreEqual(GetExcelIPAddress(worksheet, "To"), cidr.LastMatchingAddress);
            }
        }
示例#3
0
        public void Cidr_GetHashCode_Returns_Same_Value_For_Equals_CIDRs()
        {
            var obj1 = Cidr.Parse("1.2.3.4/32");
            var obj2 = Cidr.Parse("1.2.3.4/32");

            Assert.AreEqual(obj1.GetHashCode(), obj2.GetHashCode());
        }
示例#4
0
        public void B()
        {
            var a = Cidr.Parse("92.223.126.204/32");

            Assert.Equal(32, a.Suffix);
            Assert.Equal(IPAddress.Parse("92.223.126.204"), a.Start);
            Assert.Equal(IPAddress.Parse("92.223.126.204"), a.End);
        }
示例#5
0
        public void Cidr_Equals_Returns_True_When_Properties_Match()
        {
            var obj1 = Cidr.Parse("1.2.3.4/32");
            var obj2 = Cidr.Parse("1.2.3.4/32");
            var obj3 = Cidr.Parse("5.6.7.8/32");
            var obj4 = Cidr.Parse("1.2.3.4/31");

            Assert.IsTrue(obj1.Equals(obj1));
            Assert.IsTrue(obj1.Equals(obj2));

            Assert.IsFalse(obj1.Equals(null));
            Assert.IsFalse(obj1.Equals(obj3));
            Assert.IsFalse(obj1.Equals(obj4));
        }
示例#6
0
        public void Cidr_Matches_Compares_Addresses_Correctly()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            // Uncomment this block if you want to restrict the test to just those rows with a RunThis of true
            // var runThis = worksheet.NBool("RunThis").GetValueOrDefault();
            // if(!runThis) Assert.Fail();

            var cidr    = Cidr.Parse(worksheet.String("CIDR"));
            var address = GetExcelIPAddress(worksheet, "Address");

            var expected = worksheet.Bool("Result");
            var actual   = cidr.Matches(address);

            Assert.AreEqual(expected, actual);
        }
示例#7
0
        /// <summary>
        /// See interface docs.
        /// </summary>
        /// <param name="access"></param>
        public void Initialise(Access access)
        {
            if (access == null)
            {
                throw new ArgumentNullException("access");
            }

            lock (_SyncLock) {
                _Initialised   = true;
                _DefaultAccess = access.DefaultAccess;

                _Cidrs = new List <Cidr>();
                foreach (var address in access.Addresses)
                {
                    _Cidrs.Add(Cidr.Parse(address));
                }

                Access = access;
            }
        }