Ejemplo n.º 1
0
        private static string GetFieldType(PropDef propDef)
        {
            string fieldType = "varchar(50)";

            switch (propDef.PropertyTypeName.ToUpper())
            {
            case "DATETIME":
                fieldType = "datetime";
                break;

            case "STRING":
                int            length   = 50;
                PropRuleString propRule = null;
                if (propDef.PropRules.Count > 0)
                {
                    propRule = propDef.PropRules[0] as PropRuleString;
                }
                if (propRule != null)
                {
                    length = propRule.MaxLength;
                }
                if (length <= 0)
                {
                    length = 50;
                }
                fieldType = "varchar(" + length + ")";
                break;

            case "GUID":
                fieldType = "char(38)";
                break;

            case "IMAGE":
                fieldType = "blob";
                break;

            case "BOOL":
            case "BOOLEAN":
                fieldType = "tinyint(1)";    // " unsigned";
                break;

            case "INT":
            case "INTEGER":
                fieldType = "integer";
                break;

            case "SINGLE":
            case "DOUBLE":
                fieldType = "float";
                break;
            }
            return(fieldType.ToUpper());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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);
        }
        public void Test_GenerateValue_WhenStringAndMaxLength_ShouldRetToValidValue()
        {
            IPropDef def = new PropDefFake {
                PropertyType = typeof(string)
            };

            def.AddPropRule(CreatePropRuleString(3, 7));
            ValidValueGenerator generator = new ValidValueGeneratorString(def);

            Assert.AreSame(typeof(string), def.PropertyType);
            Assert.IsNotEmpty(def.PropRules.OfType <PropRuleString>().ToList());
            PropRuleString propRule = def.PropRules.OfType <PropRuleString>().First();

            Assert.AreEqual(3, propRule.MinLength);
            Assert.AreEqual(7, propRule.MaxLength);
            object value = generator.GenerateValidValue();

            Assert.IsNotNull(value);
            Assert.GreaterOrEqual(value.ToString().Length, 3);
            Assert.LessOrEqual(value.ToString().Length, 7);
        }
        private string GenerateValidValueTyped()
        {
            PropRuleString propRule = base.GetPropRule <PropRuleString>();

            return((propRule == null) ? RandomValueGen.GetRandomString() : RandomValueGen.GetRandomString(propRule.MinLength, propRule.MaxLength));
        }