示例#1
0
        public void TestStringSchemaMinMaxLengthValid()
        {
            StringSchema schema = new StringSchema {
                MinLength = 2, MaxLength = 5
            };

            schema.Validate("12");
            schema.Validate("123");
            schema.Validate("1234");
            schema.Validate("12345");
        }
示例#2
0
        public void TestStringSchemaMinMaxLengthInvalidMax()
        {
            StringSchema schema = new StringSchema {
                MinLength = 2, MaxLength = 5
            };

            schema.Validate("12");
            schema.Validate("123");
            schema.Validate("1234");
            schema.Validate("12345");
            Assert.Throws <PropertyValidationException>(() => { schema.Validate("123456"); });
        }
示例#3
0
        public void TestStringSchemaMinLengthInvalidEmpty()
        {
            StringSchema schema = new StringSchema {
                MinLength = 2
            };

            Assert.Throws <PropertyValidationException>(() => { schema.Validate(string.Empty); });
        }
示例#4
0
        public void TestStringSchemaSetInvalidValueType()
        {
            StringSchema schema = new StringSchema();

            Assert.Throws <PropertyValidationException>(() => {
                schema.Validate(1);
            });
        }
示例#5
0
        public void TestStringSchemaAllowNull()
        {
            StringSchema schema = new StringSchema {
                AllowNull = true
            };

            schema.Validate(null);
        }
示例#6
0
        public void TestStringSchemaAllowedValuesValid()
        {
            StringSchema schema = new StringSchema
            {
                PossibleValues = new[] { "one", "two", "three", "four" }
            };

            schema.Validate("three");
        }
示例#7
0
        public void TestStringSchemaNoNullAllowed()
        {
            StringSchema schema = new StringSchema {
                AllowNull = false
            };

            Assert.Throws <PropertyValidationException>(() =>
            {
                schema.Validate(null);
            });
        }
示例#8
0
        public void TestStringSchemaAllowedValuesInvalid()
        {
            StringSchema schema = new StringSchema
            {
                PossibleValues = new[] { "one", "two", "three", "four" }
            };

            Assert.Throws <PropertyValidationException>(() =>
            {
                schema.Validate("five");
            });
        }
示例#9
0
        public void TestStringSchemaMaxLengthValid()
        {
            StringSchema schema = new StringSchema {
                MaxLength = 5
            };

            schema.Validate(string.Empty);
            schema.Validate("1");
            schema.Validate("12");
            schema.Validate("123");
            schema.Validate("1234");
            schema.Validate("12345");
        }
示例#10
0
        public void TestStringSchemaValidValue()
        {
            StringSchema schema = new StringSchema();

            schema.Validate("hello");
        }