public void AttributeWithIntDomainInConstructorCreatesValidator()
        {
            object[] domain = new object[] { 1, 2, 3 };
            ValidatorAttribute attribute = new DomainValidatorAttribute(1, 2, 3);

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

            DomainValidator<object> typedValidator = validator as DomainValidator<object>;
            Assert.IsNotNull(typedValidator);

            Assert.AreEqual(Resources.DomainNonNegatedDefaultMessageTemplate, typedValidator.MessageTemplate);
            Assert.AreEqual(false, typedValidator.Negated);
            Assert.AreEqual(3, typedValidator.Domain.Count);
        }
        public void ValidatingWithValidatorAttributeWithARulesetSkipsValidation()
        {
            ValidationAttribute attribute =
                new DomainValidatorAttribute(new object[] { "a", "b", "c" })
                {
                    MessageTemplate = "template {1}",
                    Ruleset = "some ruleset"
                };

            Assert.IsTrue(attribute.IsValid("z"));
        }
        public void CanUseAttributeAsValidationAttribute()
        {
            ValidationAttribute attribute =
                new DomainValidatorAttribute(new object[] { "a", "b", "c" })
                {
                    MessageTemplate = "template {1}"
                };

            Assert.IsFalse(attribute.IsValid("z"));
            Assert.AreEqual("template name", attribute.FormatErrorMessage("name"));
        }
        public void CanUseAttributeAsValidationAttributeForValidValue()
        {
            ValidationAttribute attribute =
                new DomainValidatorAttribute(new object[] { "a", "b", "c" })
                {
                    MessageTemplate = "template {1}"
                };

            Assert.IsTrue(attribute.IsValid("a"));
        }
        public void AttributeWithStringDomainAndMessageTemplateCreatesValidator()
        {
            object[] domain = new object[] { "a", "b", "c" };

            DomainValidatorAttribute attribute = new DomainValidatorAttribute(domain);
            attribute.MessageTemplate = "my message template";

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

            DomainValidator<object> typedValidator = validator as DomainValidator<object>;
            Assert.IsNotNull(typedValidator);

            Assert.AreEqual("my message template", typedValidator.MessageTemplate);
            Assert.AreEqual(false, typedValidator.Negated);
            Assert.AreEqual(3, typedValidator.Domain.Count);
        }
        public void AttributeWithStringDomainAndNegatedCreatesValidator()
        {
            object[] domain = new object[] { "a", "b", "c" };

            DomainValidatorAttribute attribute = new DomainValidatorAttribute(domain);
            attribute.Negated = true;

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

            DomainValidator<object> typedValidator = validator as DomainValidator<object>;
            Assert.IsNotNull(typedValidator);

            Assert.AreEqual(Resources.DomainNegatedDefaultMessageTemplate, typedValidator.MessageTemplate);
            Assert.AreEqual(true, typedValidator.Negated);
            Assert.AreEqual(3, typedValidator.Domain.Count);
        }