public static void Validation_throws_ValidationException_for_invalid_strings()
 {
     var attribute = new StringLengthAttribute(12);
     Assert.Throws<ValidationException>(() => attribute.Validate("Invalid string", s_testValidationContext)); // string too long
     attribute.MinimumLength = 8;
     Assert.Throws<ValidationException>(() => attribute.Validate("Invalid", s_testValidationContext)); // string too short
 }
Пример #2
0
        public static void Validation_throws_ValidationException_for_invalid_strings()
        {
            var attribute = new StringLengthAttribute(12);

            Assert.Throws <ValidationException>(() => attribute.Validate("Invalid string", s_testValidationContext)); // string too long
            attribute.MinimumLength = 8;
            Assert.Throws <ValidationException>(() => attribute.Validate("Invalid", s_testValidationContext));        // string too short
        }
        public static void Validation_successful_for_valid_strings()
        {
            var attribute = new StringLengthAttribute(12);
            AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext)); // null is valid
            AssertEx.DoesNotThrow(() => attribute.Validate(string.Empty, s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid string", s_testValidationContext));

            attribute.MinimumLength = 5;
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid string", s_testValidationContext));
        }
Пример #4
0
        public static void Validation_successful_for_valid_strings()
        {
            var attribute = new StringLengthAttribute(12);

            AssertEx.DoesNotThrow(() => attribute.Validate(null, s_testValidationContext)); // null is valid
            AssertEx.DoesNotThrow(() => attribute.Validate(string.Empty, s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid string", s_testValidationContext));

            attribute.MinimumLength = 5;
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid", s_testValidationContext));
            AssertEx.DoesNotThrow(() => attribute.Validate("Valid string", s_testValidationContext));
        }
 public static void ValidationThrowsIf_minimum_is_greater_than_maximum()
 {
     var attribute = new StringLengthAttribute(42);
     attribute.MinimumLength = 43;
     Assert.Throws<InvalidOperationException>(
         () => attribute.Validate("Does not matter - MinimumLength > MaximumLength", s_testValidationContext));
 }
 public static void Validation_throws_InvalidOperationException_for_maximum_less_than_zero()
 {
     var attribute = new StringLengthAttribute(-1);
     Assert.Equal(-1, attribute.MaximumLength);
     Assert.Throws<InvalidOperationException>(
         () => attribute.Validate("Does not matter - MaximumLength < 0", s_testValidationContext));
 }
Пример #7
0
        public static void ValidationThrowsIf_minimum_is_greater_than_maximum()
        {
            var attribute = new StringLengthAttribute(42);

            attribute.MinimumLength = 43;
            Assert.Throws <InvalidOperationException>(
                () => attribute.Validate("Does not matter - MinimumLength > MaximumLength", s_testValidationContext));
        }
Пример #8
0
        public static void Validation_throws_InvalidOperationException_for_maximum_less_than_zero()
        {
            var attribute = new StringLengthAttribute(-1);

            Assert.Equal(-1, attribute.MaximumLength);
            Assert.Throws <InvalidOperationException>(
                () => attribute.Validate("Does not matter - MaximumLength < 0", s_testValidationContext));
        }
Пример #9
0
        public static void ValidationThrowsIf_value_passed_is_non_null_non_string()
        {
            var attribute = new StringLengthAttribute(42);

            Assert.Throws <InvalidCastException>(() => attribute.Validate(new object(), s_testValidationContext));
        }
 public static void ValidationThrowsIf_value_passed_is_non_null_non_string()
 {
     var attribute = new StringLengthAttribute(42);
     Assert.Throws<InvalidCastException>(() => attribute.Validate(new object(), s_testValidationContext));
 }