protected override void Arrange()
        {
            base.Arrange();
            var section = new ValidationSettings()
            {
                Types =
                  {
                      new ValidatedTypeReference(typeof (given_string_length_validator_with_lower_greater_than_upper))
                      {
                          Rulesets =
                          {
                              new ValidationRulesetData("ruleSet")
                              {
                                  Validators =
                                  {
                                      new AndCompositeValidatorData("AndComposite1")
                                      {
                                          Validators =
                                          {
                                              new StringLengthValidatorData() { LowerBound = 10, UpperBound = 0, LowerBoundType = Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeBoundaryType.Inclusive}
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  }

            };

            ValidationViewModel = SectionViewModel.CreateSection(Container, ValidationSettings.SectionName, section);
            Container.Resolve<ElementLookup>().AddSection(ValidationViewModel);
        }
 ///<summary>
 ///</summary>
 ///<param name="validationSettings"></param>
 ///<param name="memberAccessValidatorFactory"></param>
 ///<param name="validatorFactory"></param>
 public ConfigurationValidatorBuilder(
     ValidationSettings validationSettings,
     MemberAccessValidatorBuilderFactory memberAccessValidatorFactory,
     ValidatorFactory validatorFactory)
     : base(memberAccessValidatorFactory, validatorFactory)
 {
     this.validationSettings = validationSettings;
 }
 ///<summary>
 ///</summary>
 ///<param name="validationSettings"></param>
 ///<param name="instrumentationProvider"></param>
 public ConfigurationValidatorBuilder(
     ValidationSettings validationSettings,
     IValidationInstrumentationProvider instrumentationProvider)
     : this(
         validationSettings,
         instrumentationProvider,
         MemberAccessValidatorBuilderFactory.Default,
         ValidationFactory.DefaultCompositeValidatorFactory)
 { }
        protected override void Arrange()
        {
            base.Arrange();

            ValidationSection = new ValidationSettings();
            ValidationSection.Types.Add(new ValidatedTypeReference(typeof(String))
            {
                Rulesets = 
                {
                    { 
                        new ValidationRulesetData("string-rules")
                        {
                            Properties = 
                            {
                                new ValidatedPropertyReference("Length")
                                {
                                    Validators = 
                                    {
                                        new RangeValidatorData("RG-validator")
                                    }
                                }
                            },
                            Validators = 
                            {
                                new StringLengthValidatorData("SL-validator")
                            }
                        }
                    }
                }
            });
            ValidationSection.Types.Add(new ValidatedTypeReference(typeof(int))
            {
                Rulesets = 
                {
                    { 
                        new ValidationRulesetData("int-rules")
                        {
                            Properties = 
                            {
                                new ValidatedPropertyReference("Length")
                                {
                                    Validators = 
                                    {
                                        new RangeValidatorData("RG-validator")
                                    }
                                }
                            },
                            Validators = 
                            {
                                new StringLengthValidatorData("SL-validator")
                            }
                        }
                    }
                }
            });
        }
 ///<summary>
 ///</summary>
 ///<param name="validationSettings"></param>
 ///<param name="instrumentationProvider"></param>
 ///<param name="memberAccessValidatorFactory"></param>
 ///<param name="validatorFactory"></param>
 public ConfigurationValidatorBuilder(
     ValidationSettings validationSettings,
     IValidationInstrumentationProvider instrumentationProvider,
     MemberAccessValidatorBuilderFactory memberAccessValidatorFactory,
     ValidatorFactory validatorFactory)
     : base(memberAccessValidatorFactory, validatorFactory)
 {
     this.validationSettings = validationSettings;
     this.instrumentationProvider = instrumentationProvider;
 }
        public void CanDeserializeSerializedEmptySection()
        {
            ValidationSettings rwSettings = new ValidationSettings();
            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                ValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as ValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(0, roSettings.Types.Count);
            }
        }
        public void CanDeserializeSerializedSectionWithEmptyType()
        {
            ValidationSettings rwSettings = new ValidationSettings();
            rwSettings.Types.Add(new ValidatedTypeReference(typeof(string)));

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                ValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as ValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Types.Count);
                Assert.AreEqual(typeof(string).FullName, roSettings.Types.Get(0).Name);
                Assert.AreEqual("", roSettings.Types.Get(0).DefaultRuleset);
            }
        }
        protected override void Arrange()
        {
            base.Arrange();

            var assemblyDiscoveryService = new Mock<IAssemblyDiscoveryService>();
            Container.RegisterInstance(assemblyDiscoveryService.Object);

            var section = new ValidationSettings()
            {
                Types =
                  {
                      new ValidatedTypeReference(typeof (when_laying_out_second_level_rules))
                      {
                          Rulesets =
                          {
                              new ValidationRulesetData("ruleSet")
                              {
                                  Validators =
                                  {
                                      new AndCompositeValidatorData("AndComposite1")
                                      {
                                          Validators =
                                          {
                                              new AndCompositeValidatorData(DeepestRuleValidatorName)
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  }

            };

            ValidationViewModel = SectionViewModel.CreateSection(Container, ValidationSettings.SectionName, section);
            Container.Resolve<ElementLookup>().AddSection(ValidationViewModel);
        }       
        public void Given()
        {
            container = new UnityContainer();
            var configurationSource = new DictionaryConfigurationSource();
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(BaseTestDomainObject));
            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "RuleA";
            ValidationRulesetData ruleData = new ValidationRulesetData("RuleA");
            typeReference.Rulesets.Add(ruleData);
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("Property1");
            ruleData.Properties.Add(propertyReference1);
            MockValidatorData validator11 = new MockValidatorData("validator1", true);
            propertyReference1.Validators.Add(validator11);
            validator11.MessageTemplate = "message-from-config1-RuleA";
            MockValidatorData validator12 = new MockValidatorData("validator2", true);
            propertyReference1.Validators.Add(validator12);
            validator12.MessageTemplate = "message-from-config2-RuleA";
            MockValidatorData validator13 = new MockValidatorData("validator3", false);
            propertyReference1.Validators.Add(validator13);
            validator13.MessageTemplate = "message-from-config3-RuleA";

            var typeRegistrationProvider = new ValidationTypeRegistrationProvider();
            var configurator = new UnityContainerConfigurator(container);
            configurator.RegisterAll(configurationSource, typeRegistrationProvider);
        }
        public void CanDeserializeSerializedSectionWithNamedRuleSpecifyingMultipleValidatorsForField()
        {
            ValidationSettings rwSettings = new ValidationSettings();
            ValidatedTypeReference rwStringType = new ValidatedTypeReference(typeof(string));
            rwSettings.Types.Add(rwStringType);
            ValidationRulesetData rwValidationRule = new ValidationRulesetData("ruleset");
            rwStringType.Rulesets.Add(rwValidationRule);
            ValidatorData rwValidatorData = new MockValidatorData("validator1", true);
            rwValidationRule.Validators.Add(rwValidatorData);
            ValidatedFieldReference rwValidationFieldReference = new ValidatedFieldReference("System.Object.GetHashCode");
            rwValidationRule.Fields.Add(rwValidationFieldReference);
            ValidatorData rwFieldValidatorData1 = new MockValidatorData("ruleset-validator1", false);
            rwValidationFieldReference.Validators.Add(rwFieldValidatorData1);
            ValidatorData rwFieldValidatorData2 = new MockValidatorData("ruleset-validator2", false);
            rwValidationFieldReference.Validators.Add(rwFieldValidatorData2);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                ValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as ValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Types.Count);
                Assert.AreEqual(typeof(string).FullName, roSettings.Types.Get(0).Name);
                Assert.AreEqual(1, roSettings.Types.Get(0).Rulesets.Count);
                Assert.AreEqual("ruleset", roSettings.Types.Get(0).Rulesets.Get(0).Name);
                Assert.AreEqual(1, roSettings.Types.Get(0).Rulesets.Get(0).Validators.Count);
                Assert.AreEqual("validator1", roSettings.Types.Get(0).Rulesets.Get(0).Validators.Get(0).Name);
                Assert.AreSame(typeof(MockValidatorData), roSettings.Types.Get(0).Rulesets.Get(0).Validators.Get(0).GetType());
                Assert.AreEqual(true, ((MockValidatorData)roSettings.Types.Get(0).Rulesets.Get(0).Validators.Get(0)).ReturnFailure);
                Assert.AreEqual(1, roSettings.Types.Get(0).Rulesets.Get(0).Fields.Count);
                Assert.AreEqual("System.Object.GetHashCode", roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Name);
                Assert.AreEqual(2, roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Count);
                Assert.AreEqual("ruleset-validator1", roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Get(0).Name);
                Assert.AreSame(typeof(MockValidatorData), roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Get(0).GetType());
                Assert.AreEqual(false, ((MockValidatorData)roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Get(0)).ReturnFailure);
                Assert.AreEqual("ruleset-validator2", roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Get(1).Name);
                Assert.AreSame(typeof(MockValidatorData), roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Get(1).GetType());
                Assert.AreEqual(false, ((MockValidatorData)roSettings.Types.Get(0).Rulesets.Get(0).Fields.Get(0).Validators.Get(1)).ReturnFailure);
            }
        }
        public void CanDeserializeSerializedSectionWithTypeWithValidatorsForNamedRule()
        {
            ValidationSettings rwSettings = new ValidationSettings();
            ValidatedTypeReference rwStringType = new ValidatedTypeReference(typeof(string));
            rwSettings.Types.Add(rwStringType);
            ValidationRulesetData rwValidationRule = new ValidationRulesetData("ruleset");
            rwStringType.Rulesets.Add(rwValidationRule);
            ValidatorData rwValidatorData = new MockValidatorData("validator1", true);
            rwValidationRule.Validators.Add(rwValidatorData);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                ValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as ValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Types.Count);
                Assert.AreEqual(typeof(string).FullName, roSettings.Types.Get(0).Name);
                Assert.AreEqual(1, roSettings.Types.Get(0).Rulesets.Count);
                Assert.AreEqual("ruleset", roSettings.Types.Get(0).Rulesets.Get(0).Name);
                Assert.AreEqual(1, roSettings.Types.Get(0).Rulesets.Get(0).Validators.Count);
                Assert.AreEqual("validator1", roSettings.Types.Get(0).Rulesets.Get(0).Validators.Get(0).Name);
                Assert.AreSame(typeof(MockValidatorData), roSettings.Types.Get(0).Rulesets.Get(0).Validators.Get(0).GetType());
                Assert.AreEqual(true, ((MockValidatorData)roSettings.Types.Get(0).Rulesets.Get(0).Validators.Get(0)).ReturnFailure);
            }
        }
예제 #12
0
        public void Given()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(BaseTestDomainObject));
            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "RuleA";
            ValidationRulesetData ruleData = new ValidationRulesetData("RuleA");
            typeReference.Rulesets.Add(ruleData);
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("Property1");
            ruleData.Properties.Add(propertyReference1);
            MockValidatorData validator11 = new MockValidatorData("validator1", true);
            propertyReference1.Validators.Add(validator11);
            validator11.MessageTemplate = "message-from-config1-RuleA";
            MockValidatorData validator12 = new MockValidatorData("validator2", true);
            propertyReference1.Validators.Add(validator12);
            validator12.MessageTemplate = "message-from-config2-RuleA";
            MockValidatorData validator13 = new MockValidatorData("validator3", false);
            propertyReference1.Validators.Add(validator13);
            validator13.MessageTemplate = "message-from-config3-RuleA";

            ValidationRulesetData ruleDataB = new ValidationRulesetData("RuleB");
            typeReference.Rulesets.Add(ruleDataB);
            ValidatedPropertyReference propertyReferenceB1 = new ValidatedPropertyReference("Property1");
            ruleDataB.Properties.Add(propertyReferenceB1);
            MockValidatorData validator21 = new MockValidatorData("validator21", true);
            propertyReferenceB1.Validators.Add(validator21);
            validator21.MessageTemplate = "message-from-config1-RuleB";

            validationFactory = ConfigurationValidatorFactory.FromConfigurationSource(configurationSource);
        }
예제 #13
0
        public void Given()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(TestObjectWithFailingAttributesOnProperties));
            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "RuleA";
            ValidationRulesetData ruleData = new ValidationRulesetData("RuleA");
            typeReference.Rulesets.Add(ruleData);
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("FailingProperty1");
            ruleData.Properties.Add(propertyReference1);
            MockValidatorData validator11 = new MockValidatorData("validator1", true);
            propertyReference1.Validators.Add(validator11);
            validator11.MessageTemplate = "message-from-config1-RuleA";
            MockValidatorData validator12 = new MockValidatorData("validator2", true);
            propertyReference1.Validators.Add(validator12);
            validator12.MessageTemplate = "message-from-config2-RuleA";
            MockValidatorData validator13 = new MockValidatorData("validator3", false);
            propertyReference1.Validators.Add(validator13);
            validator13.MessageTemplate = "message-from-config3-RuleA";

            MockValidationInstrumentationProvider instrumentationProvider = new MockValidationInstrumentationProvider();

            validationFactory = new CompositeValidatorFactory(
                instrumentationProvider,
                new ValidatorFactory[]
                    {
                        new AttributeValidatorFactory(instrumentationProvider),
                        new ConfigurationValidatorFactory(configurationSource, instrumentationProvider)
                    });
        }
예제 #14
0
 ///<summary>
 ///</summary>
 ///<param name="validationSettings"></param>
 public ConfigurationValidatorBuilder(ValidationSettings validationSettings)
     : this(
         validationSettings,
         MemberAccessValidatorBuilderFactory.Default,
         ValidationFactory.DefaultCompositeValidatorFactory)
 { }
        public void CreateValidatorForNonExistingTypeInConfigurationReturnsEmptyValidator()
        {
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);

            Validator validator = builder.CreateValidator(typeof(TestClass), "ruleset1");

            Assert.IsNotNull(validator);
            Assert.AreSame(typeof(AndCompositeValidator), validator.GetType());
            IList<Validator> validators = ValidationTestHelper.CreateListFromEnumerable(((AndCompositeValidator)validator).Validators);
            Assert.AreEqual(0, validators.Count);
            Assert.AreEqual(0, mockFactory.requestedMembers.Count);
        }
        private static IConfigurationSource GetNotNullValidationConfig()
        {
            var validatorData = new NotNullValidatorData()
            {
                Name = "Not Null",
                MessageTemplate = "City cannot be null"
            };

            var fieldRef = new ValidatedFieldReference()
            {
                Name = "City"
            };

            fieldRef.Validators.Add(validatorData);

            var rulesetData = new ValidationRulesetData("default");
            rulesetData.Fields.Add(fieldRef);

            var typeData = new ValidatedTypeReference(typeof (TargetAddress));
            typeData.Rulesets.Add(rulesetData);
            typeData.DefaultRuleset = rulesetData.Name;

            var section = new ValidationSettings();
            section.Types.Add(typeData);

            var configSource = new DictionaryConfigurationSource();
            configSource.Add(BlockSectionNames.Validation, section);
            return configSource;
        }
        public void CreatedAndCompositeValidatorFromConfigAppropiately()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(BaseTestDomainObject));
            settings.Types.Add(typeReference);
            ValidationRulesetData ruleData = new ValidationRulesetData("RuleA");
            typeReference.Rulesets.Add(ruleData);
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("Property1");
            ruleData.Properties.Add(propertyReference1);
            MockValidatorData validator11 = new MockValidatorData("validator1", true);
            propertyReference1.Validators.Add(validator11);
            validator11.MessageTemplate = "message-from-config1-RuleA";

            ValidatedPropertyReference propertyReference2 = new ValidatedPropertyReference("Property2");
            ruleData.Properties.Add(propertyReference2);
            propertyReference2.Validators.Add(validator11);

            Validator validator
                = ValidationFactory.CreateValidatorFromConfiguration(typeof(BaseTestDomainObject), "RuleA", (IConfigurationSource)configurationSource);

            var validatorWrapper = validator as GenericValidatorWrapper<BaseTestDomainObject>;

            AndCompositeValidator compositeValidator = validatorWrapper.WrappedValidator as AndCompositeValidator;

            Assert.IsNotNull(compositeValidator);

            IList<Validator> allValidators = ValidationTestHelper.CreateListFromEnumerable<Validator>(compositeValidator.Validators);
            Assert.AreEqual(2, allValidators.Count);

            Assert.AreEqual(typeof(ValueAccessValidator), allValidators[0].GetType());
            Assert.AreEqual(typeof(ValueAccessValidator), allValidators[1].GetType());
        }
        public void CanBuildValidationInstanceFactoryFromGivenConfiguration()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(BaseTestDomainObject));
            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "RuleA";
            ValidationRulesetData ruleData = new ValidationRulesetData("RuleA");
            typeReference.Rulesets.Add(ruleData);
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("Property1");
            ruleData.Properties.Add(propertyReference1);
            MockValidatorData validator11 = new MockValidatorData("validator1", true);
            propertyReference1.Validators.Add(validator11);
            validator11.MessageTemplate = "message-from-config1-RuleA";

            ValidationFactory.SetDefaultConfigurationValidatorFactory(configurationSource);
            ValidatorFactory factory = ValidationFactory.DefaultCompositeValidatorFactory;

            var validator = factory.CreateValidator<BaseTestDomainObject>("RuleA");
            var results = validator.Validate(new BaseTestDomainObject());
            Assert.IsNotNull(factory);
            Assert.IsFalse(results.IsValid);
            Assert.AreEqual(validator11.MessageTemplate, results.ElementAt(0).Message);
        }
        public void CanCreateValidatorForTypeWithMultipleValidationConfigurationWithProvidedRulesetThroughTopLevelFactoryMethod()
        {
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(TestClass));
            settings.Types.Add(typeReference);
            typeReference.DefaultRuleset = "RuleB";
            ValidationRulesetData ruleDataA = new ValidationRulesetData("RuleA");
            typeReference.Rulesets.Add(ruleDataA);
            ruleDataA.Validators.Add(new MockValidatorData("validator1", false));
            ruleDataA.Validators.Get("validator1").MessageTemplate = "Message1-RuleA";
            ruleDataA.Validators.Add(new MockValidatorData("validator2", false));
            ruleDataA.Validators.Get("validator2").MessageTemplate = "Message2-RuleA";
            ruleDataA.Validators.Add(new MockValidatorData("validator3", false));
            ruleDataA.Validators.Get("validator3").MessageTemplate = "Message3-RuleA";
            ValidationRulesetData ruleDataB = new ValidationRulesetData("RuleB");
            typeReference.Rulesets.Add(ruleDataB);
            ruleDataB.Validators.Add(new MockValidatorData("validator1", false));
            ruleDataB.Validators.Get("validator1").MessageTemplate = "Message1-RuleB";
            ruleDataB.Validators.Add(new MockValidatorData("validator2", false));
            ruleDataB.Validators.Get("validator2").MessageTemplate = "Message1-RuleB";

            // Note: Use a local builder here since the assumption was made about how and when the
            //       the builder uses the configuration source....
            var localBuilder =
                ConfigurationValidatorBuilder.FromConfiguration(
                    configurationSource,
                    mockFactory,
                    ValidationFactory.DefaultCompositeValidatorFactory);
            Validator validator = localBuilder.CreateValidator(typeof(TestClass), "RuleA");
            Assert.IsNotNull(validator);
            CompositeValidatorBuilder compositeValidatorBuilder = mockFactory.requestedTypes["TestClass"];

            Assert.IsNotNull(compositeValidatorBuilder);
            Assert.AreEqual(false, compositeValidatorBuilder.IgnoreNulls);
            Assert.AreEqual(CompositionType.And, compositeValidatorBuilder.CompositionType);
            IDictionary<string, MockValidator<object>> valueValidators = ValidationTestHelper.CreateMockValidatorsMapping(compositeValidatorBuilder.ValueValidators);
            Assert.AreEqual(3, valueValidators.Count);
            Assert.IsTrue(valueValidators.ContainsKey("Message1-RuleA"));
            Assert.IsTrue(valueValidators.ContainsKey("Message2-RuleA"));
            Assert.IsTrue(valueValidators.ContainsKey("Message3-RuleA"));
        }
        public void CreateValidatorPropertyForExistingTypeInConfigurationRetunsAppropriateValidatorBasedOnRule()
        {
            ValidationSettings settings = new ValidationSettings();
            configurationSource.Add(ValidationSettings.SectionName, settings);
            ValidatedTypeReference typeReference = new ValidatedTypeReference(typeof(TestClass));
            settings.Types.Add(typeReference);
            ValidationRulesetData ruleData = new ValidationRulesetData("ruleset1");
            typeReference.Rulesets.Add(ruleData);
            ValidatedMethodReference methodReference1 = new ValidatedMethodReference("PublicMethod");
            ruleData.Methods.Add(methodReference1);
            ValidatedMethodReference methodReference2 = new ValidatedMethodReference("NonPublicMethod");
            ruleData.Methods.Add(methodReference2);
            methodReference1.Validators.Add(new MockValidatorData("validator1", false));
            methodReference1.Validators.Get("validator1").MessageTemplate = "validator 1 message";
            methodReference2.Validators.Add(new MockValidatorData("validator2", false));
            methodReference2.Validators.Get("validator2").MessageTemplate = "validator 2 message";

            // Note: Use a local builder here since the assumption was made about how and when the
            //       the builder uses the configuration source....
            var localBuilder =
                ConfigurationValidatorBuilder.FromConfiguration(
                    configurationSource,
                    mockFactory,
                    ValidationFactory.DefaultCompositeValidatorFactory);
            Validator validator = localBuilder.CreateValidator(typeof(TestClass), "ruleset1");

            Assert.IsNotNull(validator);
            Assert.AreSame(typeof(ValueAccessValidator), validator.GetType());
            ValueAccessValidatorBuilder valueAccessValidatorBuilder1 = mockFactory.requestedMembers["TestClass.PublicMethod"];
            Assert.AreSame(valueAccessValidatorBuilder1.BuiltValidator, validator);
            Assert.AreEqual("validator 1 message", ((MockValidator<object>)valueAccessValidatorBuilder1.ValueValidators[0]).MessageTemplate);
        }