예제 #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));
 }