public void AttributeWithEnumTypeCreatesValidator()
        {
            ValidatorAttribute attribute = new EnumConversionValidatorAttribute(typeof(MockEnumValidator));

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

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

            Assert.AreEqual(Resources.EnumConversionNonNegatedDefaultMessageTemplate, validator.MessageTemplate);
            Assert.AreEqual(typeof(MockEnumValidator), typedValidator.EnumType);
            Assert.AreEqual(false, typedValidator.Negated);
        }
        public void AttributeWithEnumTypeAndMessageTemplateCreatesValidator()
        {
            ValidatorAttribute attribute = new EnumConversionValidatorAttribute(typeof(MockEnumValidator));
            attribute.MessageTemplate = "my message template";

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

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

            Assert.AreEqual("my message template", validator.MessageTemplate);
            Assert.AreEqual(typeof(MockEnumValidator), typedValidator.EnumType);
            Assert.AreEqual(false, typedValidator.Negated);
        }
        public void CanUseAttributeAsValidationAttributeForValidValue()
        {
            ValidationAttribute attribute =
                new EnumConversionValidatorAttribute(typeof(MockEnumValidator))
                {
                    MessageTemplate = "template {1}"
                };

            Assert.IsTrue(attribute.IsValid("MyEnumValue"));
        }
        public void ValidatingWithValidatorAttributeWithARulesetSkipsValidation()
        {
            ValidationAttribute attribute =
                new EnumConversionValidatorAttribute(typeof(MockEnumValidator))
                {
                    MessageTemplate = "template {1}",
                    Ruleset = "some ruleset"
                };

            Assert.IsTrue(attribute.IsValid("invalid"));
        }
        public void CanUseAttributeAsValidationAttribute()
        {
            ValidationAttribute attribute =
                new EnumConversionValidatorAttribute(typeof(MockEnumValidator))
                {
                    MessageTemplate = "template {1}"
                };

            Assert.IsFalse(attribute.IsValid("invalid"));
            Assert.AreEqual("template name", attribute.FormatErrorMessage("name"));
        }