Exemple #1
0
        public void TryParseIPv4IsSuccessful()
        {
            string outputIP = string.Empty;
            bool   success;

            success = MHString.TryParseIPv4("1.1.1.1", out outputIP);
            Assert.IsTrue(success, "TryParse failed with 1.1.1.1");
            Assert.AreEqual("1.1.1.1", outputIP, "normalized ip not 1.1.1.1");

            success = MHString.TryParseIPv4("01.01.01.01", out outputIP);
            Assert.IsTrue(success, "TryParse failed with leading zeros");
            Assert.AreEqual("1.1.1.1", outputIP, "normalized ip not 1.1.1.1");

            success = MHString.TryParseIPv4("1.1.1", out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with 1.1.1");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with 1.1.1");

            success = MHString.TryParseIPv4("1.1.1.1.1", out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with 1.1.1.1.1");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with 1.1.1.1.1");

            success = MHString.TryParseIPv4(null, out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with null");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with null");

            success = MHString.TryParseIPv4(string.Empty, out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with empty");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with empty");

            success = MHString.TryParseIPv4("   ", out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with whitespace");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with whitespace");

            success = MHString.TryParseIPv4("1.1.1.A", out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with 1.1.1.A");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with 1.1.1.A");

            success = MHString.TryParseIPv4("1.1.256.1", out outputIP);
            Assert.IsFalse(success, "TryParse succeeded with 1.1.256.1");
            Assert.AreEqual(string.Empty, outputIP, "normalized ip not empty with 1.1.256.1");
        }