public void GetClientValidationRules_ReturnsMinRangeValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "Integer"); DigitsAdapter adapter = new DigitsAdapter(metadata, new ControllerContext(), new DigitsAttribute()); String errorMessage = new DigitsAttribute().FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); ModelClientValidationRule expected = new ModelClientValidationRule(); expected.ErrorMessage = errorMessage; expected.ValidationType = "digits"; Assert.Equal(expected.ValidationParameters.Count, actual.ValidationParameters.Count); Assert.Equal(expected.ValidationType, actual.ValidationType); Assert.Equal(expected.ErrorMessage, actual.ErrorMessage); }
public void GetClientValidationRules_ReturnsMinRangeValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "MinValue"); MinValueAdapter adapter = new MinValueAdapter(metadata, new ControllerContext(), new MinValueAttribute(128)); String expectedMessage = new MinValueAttribute(128).FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(128M, actual.ValidationParameters["min"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("range", actual.ValidationType); Assert.Single(actual.ValidationParameters); }
public void GetClientValidationRules_ReturnsMaxRangeValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "MaxValue"); MaxValueAdapter adapter = new MaxValueAdapter(metadata, new ControllerContext(), new MaxValueAttribute(128)); String errorMessage = new MaxValueAttribute(128).FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); ModelClientValidationRule expected = new ModelClientValidationRule(); expected.ValidationParameters.Add("max", 128M); expected.ErrorMessage = errorMessage; expected.ValidationType = "range"; Assert.Equal(expected.ValidationParameters["max"], actual.ValidationParameters["max"]); Assert.Equal(expected.ValidationParameters.Count, actual.ValidationParameters.Count); Assert.Equal(expected.ValidationType, actual.ValidationType); Assert.Equal(expected.ErrorMessage, actual.ErrorMessage); }
public void GetClientValidationRules_ReturnsFileSizeValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "FileSize"); FileSizeAdapter adapter = new FileSizeAdapter(metadata, new ControllerContext(), new FileSizeAttribute(12.25)); String errorMessage = new FileSizeAttribute(12.25).FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(12845056.00M, actual.ValidationParameters["max"]); Assert.Equal(1, actual.ValidationParameters.Count); Assert.Equal("filesize", actual.ValidationType); Assert.Equal(errorMessage, actual.ErrorMessage); }
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 void GetClientValidationRules_ReturnsEqualToValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "EqualTo"); EqualToAdapter adapter = new EqualToAdapter(metadata, new ControllerContext(), new EqualToAttribute("StringLength")); String expectedMessage = new EqualToAttribute("StringLength").FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal("*.StringLength", actual.ValidationParameters["other"]); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("equalto", actual.ValidationType); Assert.Single(actual.ValidationParameters); }
public void GetClientValidationRules_ReturnsAcceptFilesValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "AcceptFiles"); AcceptFilesAdapter adapter = new AcceptFilesAdapter(metadata, new ControllerContext(), new AcceptFilesAttribute(".docx,.rtf")); String expectedMessage = new AcceptFilesAttribute(".docx,.rtf").FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(".docx,.rtf", actual.ValidationParameters["extensions"]); Assert.Equal("acceptfiles", actual.ValidationType); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Single(actual.ValidationParameters); }