public void MaxValueAttribute_ForDouble() { Decimal actual = new MaxValueAttribute(12.56).Maximum; Decimal expected = 12.56M; Assert.Equal(expected, actual); }
public void MaxValueAttribute_ForInteger() { Decimal actual = new MaxValueAttribute(10).Maximum; Decimal expected = 10M; Assert.Equal(expected, actual); }
public void FormatErrorMessage_ForDouble() { attribute = new MaxValueAttribute(13.44); String expected = String.Format(Validations.MaxValue, "Sum", attribute.Maximum); String actual = attribute.FormatErrorMessage("Sum"); Assert.Equal(expected, actual); }
public void FormatErrorMessage_ForInteger() { attribute = new MaxValueAttribute(10); String expected = String.Format(Validations.FieldMustBeLessOrEqualTo, "Sum", attribute.Maximum); String actual = attribute.FormatErrorMessage("Sum"); Assert.Equal(expected, actual); }
public void GetClientValidationRules_ReturnsMaxRangeValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "MaxValue"); MaxValueAdapter adapter = new MaxValueAdapter(metadata, new ControllerContext(), new MaxValueAttribute(128)); String expectedMessage = new MaxValueAttribute(128).FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(128M, actual.ValidationParameters["max"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("range", actual.ValidationType); Assert.Single(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 MaxValueAttributeTests() { attribute = new MaxValueAttribute(12.56); }