public void IntegerAttribute_SetsErrorMessage() { attribute = new IntegerAttribute(); String expected = String.Format(Validations.FieldMustBeInteger, "Test"); String actual = attribute.FormatErrorMessage("Test"); Assert.Equal(expected, actual); }
public void GetClientValidationRules_ReturnsIntegerValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "Integer"); IntegerAdapter adapter = new IntegerAdapter(metadata, new ControllerContext(), new IntegerAttribute()); String expectedMessage = new IntegerAttribute().FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("integer", actual.ValidationType); Assert.Empty(actual.ValidationParameters); }
public IAttributeAdapter?GetAttributeAdapter(ValidationAttribute attribute, IStringLocalizer?stringLocalizer) { return(attribute switch { StringLengthAttribute stringLength => new StringLengthAdapter(stringLength), GreaterThanAttribute greaterThan => new GreaterThanAdapter(greaterThan), AcceptFilesAttribute acceptFiles => new AcceptFilesAdapter(acceptFiles), MinLengthAttribute minLength => new MinLengthAdapter(minLength), EmailAddressAttribute email => new EmailAddressAdapter(email), RequiredAttribute required => new RequiredAdapter(required), MaxValueAttribute maxValue => new MaxValueAdapter(maxValue), MinValueAttribute minValue => new MinValueAdapter(minValue), LessThanAttribute lessThan => new LessThanAdapter(lessThan), FileSizeAttribute fileSize => new FileSizeAdapter(fileSize), EqualToAttribute equalTo => new EqualToAdapter(equalTo), IntegerAttribute integer => new IntegerAdapter(integer), DigitsAttribute digits => new DigitsAdapter(digits), NumberAttribute number => new NumberAdapter(number), RangeAttribute range => new RangeAdapter(range), _ => null });
public IntegerAttributeTests() { attribute = new IntegerAttribute(); }