コード例 #1
0
        public void TestIpV6()
        {
            var attrib = new WIpAttribute();
            Assert.IsTrue(attrib.IsValid("::1"));
            Assert.IsTrue(attrib.IsValid("fe80::20c:29ff:fe09:ebc8"));
            Assert.IsTrue(attrib.IsValid("805B:2D9D:DC28:0000:0000:0000:D4C8:1FFF"));
            Assert.IsTrue(attrib.IsValid("805B:2D9D:DC28:0:0:0:D4C8:1FFF"));
            Assert.IsTrue(attrib.IsValid("FF00:4502:0:0:0:0:0:42"));
            Assert.IsTrue(attrib.IsValid("FF00:4502::42"));
            Assert.False(attrib.IsValid("805B::DC28::D4C8:1FFF"));

            var rules = attrib.GetClientValidationRules(null, null);

            Assert.IsTrue(rules.First().ErrorMessage == "Invalid IP address" || rules.First().ErrorMessage == "Endereço IP inválido");
        }
コード例 #2
0
        public void TestIpV4()
        {
            var attrib = new WIpAttribute();
            Assert.IsTrue(attrib.IsValid("192.169.1.1"));
            Assert.IsFalse(attrib.IsValid("256.1.3.4"));
            Assert.IsFalse(attrib.IsValid("023.44.33.22"));
            Assert.IsFalse(attrib.IsValid("10.57.98.23."));

            var rules = attrib.GetClientValidationRules(null, null);

            Assert.IsTrue(rules.First().ErrorMessage == "Invalid IP address" || rules.First().ErrorMessage == "Endereço IP inválido");
        }