Пример #1
0
        private static Errors ValidateProperty(PropertyInfo property, object entity, object value)
        {
            var errors = new Errors();

            RequiredAttribute.Validate(property, value, errors);
            MaxLengthAttribute.Validate(property, value, errors);
            MinLengthAttribute.Validate(property, value, errors);

            return(errors);
        }
Пример #2
0
 public void Validate_ICollection_NetCore_Invalid(MaxLengthAttribute attribute, object value)
 {
     Assert.Throws <ValidationException>(() => attribute.Validate(value, new ValidationContext(new object())));
     Assert.False(attribute.IsValid(value));
 }
Пример #3
0
 public void Validate_ICollection_NetCore_Valid(MaxLengthAttribute attribute, object value)
 {
     attribute.Validate(value, new ValidationContext(new object()));
     Assert.True(attribute.IsValid(value));
 }
Пример #4
0
        public static void GetValidationResult_InvalidLength_ThrowsInvalidOperationException(int length)
        {
            var attribute = new MaxLengthAttribute(length);

            Assert.Throws <InvalidOperationException>(() => attribute.Validate("Twoflower", new ValidationContext(new object())));
        }
Пример #5
0
 public void Validate_ICollection_NetFx_ThrowsInvalidCastException(MaxLengthAttribute attribute, object value)
 {
     Assert.Throws <InvalidCastException>(() => attribute.Validate(value, new ValidationContext(new object())));
     Assert.Throws <InvalidCastException>(() => attribute.IsValid(value));
 }