Ejemplo n.º 1
0
 public string this[string columnName]
 {
     get
     {
         if (columnName == "Username")
         {
             StringValidationRule rule = new StringValidationRule
             {
                 FieldName = columnName
             };
             ValidationResult result = rule.Validate(Username, CultureInfo.InvariantCulture);
             return((string)result.ErrorContent);
         }
         if (columnName == "ServerAddress")
         {
             return(String.IsNullOrWhiteSpace(ServerAddress) ? "Server address cannot be empty" : null);
         }
         if (columnName == "ServerPort")
         {
             NumericValidationRule rule = new NumericValidationRule
             {
                 Minimum      = 1024,
                 Maximum      = 65535,
                 PositiveOnly = true
             };
             ValidationResult result = rule.Validate(ServerPort, CultureInfo.InvariantCulture);
             return((string)result.ErrorContent);
         }
         return(null);
     }
 }
Ejemplo n.º 2
0
        public static void validateNumericFailsOnNonNumericInputs()
        {
            var numericalRule = new NumericValidationRule();

            Assert.IsFalse(numericalRule.Validate("0..10", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0..10..2", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0..10..5", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0..10..#5", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0.0..10..0.5", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("start..end", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("a..b", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("a..10", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("a", CultureInfo.InvariantCulture).IsValid);
        }
Ejemplo n.º 3
0
        public static void validateNumericPassesOnNumericInputs()
        {
            var numericalRule = new NumericValidationRule();

            Assert.IsTrue(numericalRule.Validate("10", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("2147483647", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("9223372036854775807", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate(".00000000001", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("100,000,000", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("1,2", CultureInfo.InvariantCulture).IsValid);
        }
        public static void validateNumericPassesOnNumericInputs()
        {
            var numericalRule = new NumericValidationRule();

            Assert.IsTrue(numericalRule.Validate("10", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("2147483647", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("9223372036854775807", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate(".00000000001", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("100,000,000", CultureInfo.InvariantCulture).IsValid);
            Assert.IsTrue(numericalRule.Validate("1,2", CultureInfo.InvariantCulture).IsValid);

        }
        public static void validateNumericFailsOnNonNumericInputs()
        {
            var numericalRule = new NumericValidationRule();

            Assert.IsFalse(numericalRule.Validate("0..10", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0..10..2", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0..10..5", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0..10..#5", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("0.0..10..0.5", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("start..end", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("a..b", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("a..10", CultureInfo.InvariantCulture).IsValid);
            Assert.IsFalse(numericalRule.Validate("a", CultureInfo.InvariantCulture).IsValid);

        }