Exemplo n.º 1
0
        public void ValidatesUsingTheSuppliedFactory()
        {
            object             instance           = new DerivedObjectCollectionValidatorAttributeFixtureTestClass();
            object             target             = new object[] { instance };
            ValidatorAttribute validatorAttribute = new ObjectCollectionValidatorAttribute();

            Validator validator =
                ((IValidatorDescriptor)validatorAttribute)
                .CreateValidator(null, null, null, EnterpriseLibraryContainer.Current.GetInstance <AttributeValidatorFactory>());
            ValidationResults validationResults = validator.Validate(target);

            Assert.IsFalse(validationResults.IsValid);
            IDictionary <string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);

            Assert.AreEqual(3, resultsMapping.Count);

            Assert.IsTrue(resultsMapping.ContainsKey("DerivedObjectCollectionValidatorAttributeFixtureTestClass"));
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass"].Key);
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass"].Tag);
            Assert.AreSame(instance, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass"].Target);

            Assert.IsTrue(resultsMapping.ContainsKey("ObjectCollectionValidatorAttributeFixtureTestClass-Property"));
            Assert.AreEqual("Property", resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Key);
            Assert.AreEqual(null, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Tag);
            Assert.AreSame(instance, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Target);

            Assert.IsTrue(resultsMapping.ContainsKey("DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"));
            Assert.AreEqual("DerivedProperty", resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"].Key);
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"].Tag);
            Assert.AreSame(instance, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"].Target);
        }
Exemplo n.º 2
0
        public void AttributeCreatesValidatorWithDefaultRulesetIfNoRulesetIsSupplied()
        {
            object             instance = new ObjectCollectionValidatorAttributeFixtureTestClass();
            object             target   = new object[] { instance };
            ValidatorAttribute validatorAttribute
                = new ObjectCollectionValidatorAttribute(typeof(ObjectCollectionValidatorAttributeFixtureTestClass));

            Validator validator =
                ((IValidatorDescriptor)validatorAttribute).CreateValidator(null, null, null, ValidationFactory.DefaultCompositeValidatorFactory);
            ValidationResults validationResults = validator.Validate(target);

            Assert.IsFalse(validationResults.IsValid);
            IDictionary <string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);

            Assert.AreEqual(2, resultsMapping.Count);

            Assert.IsTrue(resultsMapping.ContainsKey("ObjectCollectionValidatorAttributeFixtureTestClass"));
            Assert.AreEqual(null, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass"].Key);
            Assert.AreEqual(null, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass"].Tag);
            Assert.AreSame(instance, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass"].Target);

            Assert.IsTrue(resultsMapping.ContainsKey("ObjectCollectionValidatorAttributeFixtureTestClass-Property"));
            Assert.AreEqual("Property", resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Key);
            Assert.AreEqual(null, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Tag);
            Assert.AreSame(instance, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Target);
        }
Exemplo n.º 3
0
        public void ValidatesUsingActualTypeRulesIfTypeIsSpecified()
        {
            object             instance           = new DerivedObjectCollectionValidatorAttributeFixtureTestClass();
            object             target             = new object[] { instance };
            ValidatorAttribute validatorAttribute = new ObjectCollectionValidatorAttribute();

            Validator validator =
                ((IValidatorDescriptor)validatorAttribute).CreateValidator(null, null, null, ValidationFactory.DefaultCompositeValidatorFactory);
            ValidationResults validationResults = validator.Validate(target);

            Assert.IsFalse(validationResults.IsValid);
            IDictionary <string, ValidationResult> resultsMapping = ValidationTestHelper.GetResultsMapping(validationResults);

            Assert.AreEqual(4, resultsMapping.Count);

            Assert.IsTrue(resultsMapping.ContainsKey("DerivedObjectCollectionValidatorAttributeFixtureTestClass"));
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass"].Key);
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass"].Tag);
            Assert.AreSame(instance, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass"].Target);

            Assert.IsTrue(resultsMapping.ContainsKey("ObjectCollectionValidatorAttributeFixtureTestClass-Property"));
            Assert.AreEqual("Property", resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Key);
            Assert.AreEqual(null, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Tag);
            Assert.AreSame(instance, resultsMapping["ObjectCollectionValidatorAttributeFixtureTestClass-Property"].Target);

            Assert.IsTrue(resultsMapping.ContainsKey("DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"));
            Assert.AreEqual("DerivedProperty", resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"].Key);
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"].Tag);
            Assert.AreSame(instance, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty"].Target);

            Assert.IsTrue(resultsMapping.ContainsKey("DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty-DataAnnotations"));
            Assert.AreEqual("DerivedProperty", resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty-DataAnnotations"].Key);
            Assert.AreEqual(null, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty-DataAnnotations"].Tag);
            Assert.AreSame(instance, resultsMapping["DerivedObjectCollectionValidatorAttributeFixtureTestClass-DerivedProperty-DataAnnotations"].Target);
        }