コード例 #1
0
        public void ValidatorCanValidateSubclassOfTargetTypeUsingSubclassValidationRulesIfConfiguredToDoSo()
        {
            object           target    = new ObjectValidatorFixtureReferencedTestClassSubclass();
            ValidatorFactory factory   = new AttributeValidatorFactory();
            Validator        validator = new ObjectValidator(factory, "RuleB");

            ValidationResults validationResults = new ValidationResults();

            validator.DoValidate(target, this, "key", validationResults); // setting the currentTarget and the key

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

            Assert.AreEqual(2, resultsMapping.Count);

            Assert.IsTrue(resultsMapping.ContainsKey("PropertyInReferencedObject-RuleB"));
            Assert.AreEqual("PropertyInReferencedObject", resultsMapping["PropertyInReferencedObject-RuleB"].Key);
            Assert.AreEqual(null, resultsMapping["PropertyInReferencedObject-RuleB"].Tag);
            Assert.AreSame(target, resultsMapping["PropertyInReferencedObject-RuleB"].Target);
            Assert.AreSame(typeof(MockValidator <object>), resultsMapping["PropertyInReferencedObject-RuleB"].Validator.GetType());

            Assert.IsTrue(resultsMapping.ContainsKey("PropertyInReferencedObjectSubclass"));
            Assert.AreEqual("PropertyInReferencedObjectSubclass", resultsMapping["PropertyInReferencedObjectSubclass"].Key);
            Assert.AreEqual(null, resultsMapping["PropertyInReferencedObjectSubclass"].Tag);
            Assert.AreSame(target, resultsMapping["PropertyInReferencedObjectSubclass"].Target);
            Assert.AreSame(typeof(MockValidator <object>), resultsMapping["PropertyInReferencedObjectSubclass"].Validator.GetType());
        }
コード例 #2
0
        public void TargetObjectValidatorIsCreatedWithProvidedRuleset()
        {
            object    target    = new ObjectValidatorFixtureReferencedTestClass();
            Validator validator = new ObjectValidator(typeof(ObjectValidatorFixtureReferencedTestClass), "RuleB");

            ValidationResults validationResults = new ValidationResults();

            validator.DoValidate(target, this, "key", validationResults); // setting the currentTarget and the key

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

            Assert.AreEqual(1, resultsMapping.Count);
            Assert.IsTrue(resultsMapping.ContainsKey("PropertyInReferencedObject-RuleB"));
            Assert.AreEqual("PropertyInReferencedObject", resultsMapping["PropertyInReferencedObject-RuleB"].Key);
            Assert.AreEqual(null, resultsMapping["PropertyInReferencedObject-RuleB"].Tag);
            Assert.AreSame(target, resultsMapping["PropertyInReferencedObject-RuleB"].Target);
            Assert.AreSame(typeof(MockValidator <object>), resultsMapping["PropertyInReferencedObject-RuleB"].Validator.GetType());
        }