Exemplo n.º 1
0
        public void IsValid()
        {
            var v = new DigitsAttribute(3);

            Assert.IsTrue(v.IsValid(0, null));
            Assert.IsTrue(v.IsValid(9, null));
            Assert.IsTrue(v.IsValid(99, null));
            Assert.IsTrue(v.IsValid(99.0, null));
            Assert.IsTrue(v.IsValid(null, null));
            Assert.IsTrue(v.IsValid("22", null));
            Assert.IsTrue(v.IsValid(103, null));
            Assert.IsTrue(v.IsValid(01, null));

            Assert.IsFalse(v.IsValid(1000, null));
            Assert.IsFalse(v.IsValid(10.1, null));
            Assert.IsFalse(v.IsValid(new object(), null));
            Assert.IsFalse(v.IsValid("aa.bb", null));

            v = new DigitsAttribute(3, 2);
            Assert.IsTrue(v.IsValid(0, null));
            Assert.IsTrue(v.IsValid(1, null));
            Assert.IsTrue(v.IsValid(100.100, null));
            Assert.IsTrue(v.IsValid(99.99, null));

            Assert.IsFalse(v.IsValid(1000.0, null));
            Assert.IsFalse(v.IsValid(9.233, null));
            Assert.IsFalse(v.IsValid("1233", null));


            v = new DigitsAttribute(0, 2);
            Assert.IsTrue(v.IsValid(0, null));
            Assert.IsTrue(v.IsValid(0.12, null));
            Assert.IsTrue(v.IsValid(0.1, null));
            Assert.IsTrue(v.IsValid(0.00000000000, null));

            Assert.IsFalse(v.IsValid(1.12, null));
            Assert.IsFalse(v.IsValid(0.123, null));
        }
 public void IsValid_Null()
 {
     Assert.True(attribute.IsValid(null));
 }
Exemplo n.º 3
0
        public void IsValidTests()
        {
            var attribute = new DigitsAttribute();

            Assert.IsTrue(attribute.IsValid(null)); // Don't check for required
            Assert.IsTrue(attribute.IsValid("1234"));
            Assert.IsTrue(attribute.IsValid("12345"));
            Assert.IsTrue(attribute.IsValid(14));
            Assert.IsTrue(attribute.IsValid("6708025174"));
            Assert.IsTrue(attribute.IsValid(1000000000000000000)); //big number
            Assert.IsFalse(attribute.IsValid(14.50));
            Assert.IsFalse(attribute.IsValid(-10));                //Does not allow negative numbers
            Assert.IsFalse(attribute.IsValid("-50"));
            Assert.IsFalse(attribute.IsValid("12.90"));
            Assert.IsFalse(attribute.IsValid("1234.5"));
            Assert.IsFalse(attribute.IsValid("$3.50"));
            Assert.IsFalse(attribute.IsValid("12abc"));
            Assert.IsFalse(attribute.IsValid(DateTime.Now));
            Assert.IsFalse(attribute.IsValid("fourteen"));
        }
Exemplo n.º 4
0
        public void IsValidTests()
        {
            var attribute = new DigitsAttribute();

            Assert.IsTrue(attribute.IsValid(null)); // Don't check for required
            Assert.IsTrue(attribute.IsValid("1234"));
            Assert.IsTrue(attribute.IsValid("12345"));
            Assert.IsTrue(attribute.IsValid(14));
            Assert.IsTrue(attribute.IsValid("6708025174"));
            //really big number
            Assert.IsTrue(attribute.IsValid("23748962347868791263748163874628397458217396478192354987253468127354782163478623894761239874523"));
            Assert.IsTrue(attribute.IsValid(1000000000000000000)); //big number
            Assert.IsFalse(attribute.IsValid(14.50));
            Assert.IsFalse(attribute.IsValid(-10));                //Does not allow negative numbers
            Assert.IsFalse(attribute.IsValid("-50"));
            Assert.IsFalse(attribute.IsValid("12.90"));
            Assert.IsFalse(attribute.IsValid("1234.5"));
            Assert.IsFalse(attribute.IsValid("$3.50"));
            Assert.IsFalse(attribute.IsValid("12abc"));
            Assert.IsFalse(attribute.IsValid(DateTime.Now));
            Assert.IsFalse(attribute.IsValid("fourteen"));
        }