public void NumericValidator_GetClientValidationRules() { // Arrange ModelMetadata metadata = _metadataProvider.GetMetadataForProperty(null, typeof(SampleModel), "Int32"); var validator = new ClientDataTypeModelValidatorProvider.NumericModelValidator(metadata, new ControllerContext()); // Act ModelClientValidationRule[] rules = validator.GetClientValidationRules().ToArray(); // Assert Assert.AreEqual(1, rules.Length, "Wrong number of rules returned."); ModelClientValidationRule rule = rules[0]; Assert.AreEqual("number", rule.ValidationType); Assert.AreEqual(0, rule.ValidationParameters.Count); Assert.AreEqual("The field Int32 must be a number.", rule.ErrorMessage); }
public void NumericValidator_Validate_ReturnsEmptyCollection() { // Arrange ModelMetadata metadata = _metadataProvider.GetMetadataForType(null, typeof(object)); var validator = new ClientDataTypeModelValidatorProvider.NumericModelValidator(metadata, new ControllerContext()); // Act IEnumerable<ModelValidationResult> result = validator.Validate(null); // Assert Assert.AreEqual(0, result.Count(), "Shouldn't have been any errors."); }