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); }
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)); }
public void Validate_ICollection_NetCore_Valid(MaxLengthAttribute attribute, object value) { attribute.Validate(value, new ValidationContext(new object())); Assert.True(attribute.IsValid(value)); }
public static void GetValidationResult_InvalidLength_ThrowsInvalidOperationException(int length) { var attribute = new MaxLengthAttribute(length); Assert.Throws <InvalidOperationException>(() => attribute.Validate("Twoflower", new ValidationContext(new object()))); }
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)); }