public void AttributeWithCharacterSetAndContainsCharactersCreatesValidator()
        {
            ValidatorAttribute attribute = new ContainsCharactersValidatorAttribute("abc", ContainsCharacters.All);

            Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null);
            Assert.IsNotNull(validator);

            ContainsCharactersValidator typedValidator = validator as ContainsCharactersValidator;
            Assert.IsNotNull(typedValidator);

            Assert.AreEqual(Resources.ContainsCharactersNonNegatedDefaultMessageTemplate, typedValidator.MessageTemplate);
            Assert.AreEqual("abc", typedValidator.CharacterSet);
            Assert.AreEqual(ContainsCharacters.All, typedValidator.ContainsCharacters);
            Assert.AreEqual(false, typedValidator.Negated);
        }
        public void AttributeWithCharacterSetAndMessageOverrideCreatesValidator()
        {
            ValidatorAttribute attribute = new ContainsCharactersValidatorAttribute("abc");
            attribute.MessageTemplate = "overriden message template";

            Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null);
            Assert.IsNotNull(validator);

            ContainsCharactersValidator typedValidator = validator as ContainsCharactersValidator;
            Assert.IsNotNull(typedValidator);

            Assert.AreEqual("abc", typedValidator.CharacterSet);
            Assert.AreEqual(ContainsCharacters.Any, typedValidator.ContainsCharacters);
            Assert.AreEqual(false, typedValidator.Negated);
            Assert.AreEqual("overriden message template", typedValidator.MessageTemplate);
        }
        public void ValidatingWithValidatorAttributeWithARulesetSkipsValidation()
        {
            ValidationAttribute attribute =
                new ContainsCharactersValidatorAttribute("abc", ContainsCharacters.All)
                {
                    MessageTemplate = "template {1}",
                    Ruleset = "some ruleset"
                };

            Assert.IsTrue(attribute.IsValid("bcd"));
        }
        public void CanUseAttributeAsValidationAttribute()
        {
            ValidationAttribute attribute =
                new ContainsCharactersValidatorAttribute("abc", ContainsCharacters.All)
                {
                    MessageTemplate = "template {1}"
                };

            Assert.IsFalse(attribute.IsValid("bcd"));
            Assert.AreEqual("template name", attribute.FormatErrorMessage("name"));
        }
        public void CanUseAttributeAsValidationAttributeForValidValue()
        {
            ValidationAttribute attribute =
                new ContainsCharactersValidatorAttribute("abc", ContainsCharacters.All)
                {
                    MessageTemplate = "template {1}"
                };

            Assert.IsTrue(attribute.IsValid("cccaaabbb"));
        }
        public void AttributeWithCharacterSetAndContainsCharactersAndMessageTemplateAndNegatedCreatesValidator()
        {
            ValueValidatorAttribute attribute = new ContainsCharactersValidatorAttribute("abc", ContainsCharacters.All);
            attribute.Negated = true;
            attribute.MessageTemplate = "my message template";

            Validator validator = ((IValidatorDescriptor)attribute).CreateValidator(null, null, null, null);
            Assert.IsNotNull(validator);

            ContainsCharactersValidator typedValidator = validator as ContainsCharactersValidator;
            Assert.IsNotNull(typedValidator);

            Assert.AreEqual("my message template", typedValidator.MessageTemplate);
            Assert.AreEqual("abc", typedValidator.CharacterSet);
            Assert.AreEqual(ContainsCharacters.All, typedValidator.ContainsCharacters);
            Assert.AreEqual(true, typedValidator.Negated);
        }