예제 #1
0
        public void TestStringRule()
        {
            PropRuleString rule = new PropRuleString("Surname", "Test", 2, 50, null);

            //Test less than min length
            string errorMessage = "";
            Assert.IsFalse(rule.IsPropValueValid("Propname", "a", ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
            //Test valid data
            errorMessage = "";
            Assert.IsTrue(rule.IsPropValueValid("Propname", "fdfsdafasdfsdf", ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);
            //test greater than max length
            errorMessage = "";
            Assert.IsFalse(rule.IsPropValueValid("Propname", 
                "MySurnameIsTooLongByFarThisWill Cause and Error in Bus object", ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);

            //Test lengths and not compulsory
            rule = new PropRuleString("Surname", "Test", 10, 20, null);
            errorMessage = "";
            Assert.IsTrue(rule.IsPropValueValid("Propname", null, ref errorMessage));
            Assert.IsTrue(errorMessage.Length == 0);
            //test zero length strings
            errorMessage = "";
            Assert.IsTrue(rule.IsPropValueValid("Propname", "", ref errorMessage)); 
            Assert.IsTrue(errorMessage.Length == 0);

            //Test that it ignores negative max length
            rule = new PropRuleString("Surname", "Test", -10, -1, null);
            errorMessage = "";
            Assert.IsTrue(rule.IsPropValueValid("Propname", "", ref errorMessage)); //test zero length strings
            Assert.IsFalse(errorMessage.Length > 0);

            errorMessage = "";
            Assert.IsTrue(rule.IsPropValueValid("Propname", "ffff", ref errorMessage));
            Assert.IsFalse(errorMessage.Length > 0);

            errorMessage = "";
            Assert.IsFalse(rule.IsPropValueValid("Propname", 11, ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);

            errorMessage = "";
            Assert.IsFalse(rule.IsPropValueValid("Propname", new DateTime(2005,06,05), ref errorMessage));
            Assert.IsTrue(errorMessage.Length > 0);
        }
예제 #2
0
        public void TestStringRulePatternMatch()
        {
            //Pattern match no numeric characters allowed
            string errorMessage = "";
            PropRuleString rule = new PropRuleString("Surname", "Test", 10, 20, @"^[a-zA-Z\- ]*$");
            Assert.IsFalse(rule.IsPropValueValid("Propname", "fdfasd 3dfasdf", ref errorMessage), "fdfasd 3dfasdf");
            Assert.IsTrue(errorMessage.Length > 0);
            errorMessage = "";
            Assert.IsTrue(rule.IsPropValueValid("Propname", "fdfasd-fdf asdf", ref errorMessage), "fdfasd fdfasdf");
            Assert.IsFalse(errorMessage.Length > 0);

            Assert.IsFalse(rule.IsPropValueValid("Propname", "fdfasd", ref errorMessage), "fdfasd");
            Assert.IsTrue(errorMessage.Length > 0);
        }