public void AttributeWithResourcePatternCreatesValidatorWithPatternDefaultMessageAndNoneOptions() { ValidatorAttribute attribute = new RegexValidatorAttribute(RegexResourceName1, typeof(Properties.Resources)); Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); RegexValidator regexValidator = validator as RegexValidator; Assert.IsNotNull(regexValidator); Assert.AreEqual(null, regexValidator.Pattern); Assert.AreEqual(RegexOptions.None, regexValidator.Options); Assert.AreEqual(Resources.RegexValidatorNonNegatedDefaultMessageTemplate, regexValidator.MessageTemplate); Assert.AreEqual(RegexResourceName1, regexValidator.PatternResourceName); Assert.AreEqual(typeof(Properties.Resources), regexValidator.PatternResourceType); Assert.AreEqual(false, regexValidator.Negated); }
public void AttributeWithPatternCreatesValidatorWithPatternDefaultMessageAndNoneOptionsAndNegated() { ValueValidatorAttribute attribute = new RegexValidatorAttribute("pattern"); attribute.Negated = true; Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); RegexValidator regexValidator = validator as RegexValidator; Assert.IsNotNull(regexValidator); Assert.AreEqual("pattern", regexValidator.Pattern); Assert.AreEqual(RegexOptions.None, regexValidator.Options); Assert.AreEqual(Resources.RegexValidatorNegatedDefaultMessageTemplate, regexValidator.MessageTemplate); Assert.AreEqual(true, regexValidator.Negated); }
public void ValidatingWithValidatorAttributeWithARulesetSkipsValidation() { ValidationAttribute attribute = new RegexValidatorAttribute("^a*$") { MessageTemplate = "template {1}", Ruleset = "some ruleset" }; Assert.IsTrue(attribute.IsValid("bbbbbb")); }
public void CanUseAttributeAsValidationAttribute() { ValidationAttribute attribute = new RegexValidatorAttribute("^a*$") { MessageTemplate = "template {1}" }; Assert.IsFalse(attribute.IsValid("bbbbbb")); Assert.AreEqual("template name", attribute.FormatErrorMessage("name")); }
public void CanUseAttributeAsValidationAttributeForValidValue() { ValidationAttribute attribute = new RegexValidatorAttribute("^a*$") { MessageTemplate = "template {1}" }; Assert.IsTrue(attribute.IsValid("aaaaaaaaaa")); }
public void AttributeWithPatternOptionsAndMessageOverrideCreatesValidatorWithPatternOverridenMessageAndOptionsAndNegated() { ValueValidatorAttribute attribute = new RegexValidatorAttribute("pattern", RegexOptions.Multiline); attribute.Negated = true; attribute.MessageTemplate = "overriden message template"; Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); RegexValidator regexValidator = validator as RegexValidator; Assert.IsNotNull(regexValidator); Assert.AreEqual("pattern", regexValidator.Pattern); Assert.AreEqual(RegexOptions.Multiline, regexValidator.Options.Value); Assert.AreEqual("overriden message template", regexValidator.MessageTemplate); Assert.AreEqual(true, regexValidator.Negated); }
public void AttributeWithResourcePatternAndOptionsAndMessageTemplateCreatesValidator() { ValidatorAttribute attribute = new RegexValidatorAttribute(RegexResourceName1, typeof(Properties.Resources), RegexOptions.Multiline); attribute.MessageTemplate = "overriden message template"; Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); RegexValidator regexValidator = validator as RegexValidator; Assert.IsNotNull(regexValidator); Assert.AreEqual(null, regexValidator.Pattern); Assert.AreEqual(RegexOptions.Multiline, regexValidator.Options); Assert.AreEqual("overriden message template", regexValidator.MessageTemplate); Assert.AreEqual(RegexResourceName1, regexValidator.PatternResourceName); Assert.AreEqual(typeof(Properties.Resources), regexValidator.PatternResourceType); Assert.AreEqual(false, regexValidator.Negated); }
public void AttributeWithPatternAndOptionsCreatesValidatorWithPatternDefaultMessageAndOptions() { ValidatorAttribute attribute = new RegexValidatorAttribute("pattern", RegexOptions.Multiline); Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); RegexValidator regexValidator = validator as RegexValidator; Assert.IsNotNull(regexValidator); Assert.AreEqual("pattern", regexValidator.Pattern); Assert.AreEqual(RegexOptions.Multiline, regexValidator.Options.Value); Assert.AreEqual(Resources.RegexValidatorNonNegatedDefaultMessageTemplate, regexValidator.MessageTemplate); Assert.AreEqual(false, regexValidator.Negated); }