public void FlyweightUpdatedWithValidatedPropertyReferenceReturnsCorrectValues()
        {
            ValidatedPropertyReference propertyReference = new ValidatedPropertyReference("Property");
            propertyReference.Validators.Add(new MockValidatorData("validator1", false));
            propertyReference.Validators.Get("validator1").MessageTemplate = "property validator 1 message";
            propertyReference.Validators.Add(new MockValidatorData("validator2", false));
            propertyReference.Validators.Get("validator2").MessageTemplate = "property validator 2 message";

            ConfigurationValidatedElement validatedElement = new ConfigurationValidatedElement();
            PropertyInfo propertyInfo = typeof(ConfigurationValidatedElementFixtureTestClass).GetProperty("Property");

            validatedElement.UpdateFlyweight(propertyReference, propertyInfo);

            Assert.AreSame(typeof(string), ((IValidatedElement)validatedElement).TargetType);
            Assert.AreSame(propertyInfo, ((IValidatedElement)validatedElement).MemberInfo);
            Assert.AreEqual(CompositionType.And, ((IValidatedElement)validatedElement).CompositionType);
            Assert.AreEqual(null, ((IValidatedElement)validatedElement).CompositionMessageTemplate);
            Assert.AreEqual(false, ((IValidatedElement)validatedElement).IgnoreNulls);
            Assert.AreEqual(null, ((IValidatedElement)validatedElement).IgnoreNullsMessageTemplate);

            IEnumerator<IValidatorDescriptor> validatorDescriptorsEnumerator
                = ((IValidatedElement)validatedElement).GetValidatorDescriptors().GetEnumerator();
            Assert.IsNotNull(validatorDescriptorsEnumerator);
            Assert.IsTrue(validatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("property validator 1 message",
                            ((MockValidatorData)validatorDescriptorsEnumerator.Current).MessageTemplate);
            Assert.IsTrue(validatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("property validator 2 message",
                            ((MockValidatorData)validatorDescriptorsEnumerator.Current).MessageTemplate);
            Assert.IsFalse(validatorDescriptorsEnumerator.MoveNext());
        }
        public void CreateValidatorForPropertyReferenceWithoutValidatorsReturnsNull()
        {
            ValidatedPropertyReference propertyReference = new ValidatedPropertyReference("PublicProperty");

            Validator validator = builder.CreateValidatorForProperty(typeof(TestClass), propertyReference);

            Assert.IsNull(validator);
        }
        public void CreateValidatorForWriteOnlyPropertyReferenceWithValidatorsReturnsNull()
        {
            ValidatedPropertyReference propertyReference = new ValidatedPropertyReference("WriteOnlyPublicProperty");
            propertyReference.Validators.Add(new MockValidatorData("validator1", false));
            propertyReference.Validators.Get("validator1").MessageTemplate = "validator 1 message";
            propertyReference.Validators.Add(new MockValidatorData("validator2", false));
            propertyReference.Validators.Get("validator2").MessageTemplate = "validator 2 message";

            Validator validator = builder.CreateValidatorForProperty(typeof(TestClass), propertyReference);

            Assert.IsNull(validator);
            Assert.AreEqual(0, mockFactory.requestedMembers.Count);
        }
        public void CreateValidatorForPropertyReferenceWithValidatorsReturnsValueAccessValidator()
        {
            ValidatedPropertyReference propertyReference = new ValidatedPropertyReference("PublicProperty");
            propertyReference.Validators.Add(new MockValidatorData("validator1", false));
            propertyReference.Validators.Get("validator1").MessageTemplate = "validator 1 message";
            propertyReference.Validators.Add(new MockValidatorData("validator2", false));
            propertyReference.Validators.Get("validator2").MessageTemplate = "validator 2 message";

            Validator validator = builder.CreateValidatorForProperty(typeof(TestClass), propertyReference);

            Assert.IsNotNull(validator);
            Assert.AreEqual(1, mockFactory.requestedMembers.Count);
            ValueAccessValidatorBuilder valueAccessValidatorBuilder = mockFactory.requestedMembers["TestClass.PublicProperty"];
            Assert.AreSame(valueAccessValidatorBuilder.BuiltValidator, validator);
            Assert.AreEqual(2, valueAccessValidatorBuilder.ValueValidators.Count);
            Assert.AreEqual("validator 1 message", ((MockValidator<object>)valueAccessValidatorBuilder.ValueValidators[0]).MessageTemplate);
            Assert.AreEqual("validator 2 message", ((MockValidator<object>)valueAccessValidatorBuilder.ValueValidators[1]).MessageTemplate);
        }
        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());
        }
        /// <summary>
        /// Updates the flyweight for a property.
        /// </summary>
        /// <param name="validatedPropertyReference">The property reference configuration object.</param>
        /// <param name="propertyInfo">The property.</param>
        public void UpdateFlyweight(ValidatedPropertyReference validatedPropertyReference, PropertyInfo propertyInfo)
        {
            if (propertyInfo == null) throw new ArgumentNullException("propertyInfo");

            UpdateFlyweight(validatedPropertyReference, propertyInfo, propertyInfo.PropertyType);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationValidatedElement"/> class for a property.
 /// </summary>
 /// <param name="validatedPropertyReference">The property reference configuration object.</param>
 /// <param name="propertyInfo">The property.</param>
 public ConfigurationValidatedElement(ValidatedPropertyReference validatedPropertyReference, PropertyInfo propertyInfo)
 {
     UpdateFlyweight(validatedPropertyReference, propertyInfo);
 }
        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 ValidatedPropertiesEnumerableSkipsNonExistingPropertyWithValidators()
        {
            ValidationRulesetData rulesetData = new ValidationRulesetData();
            ValidatedPropertyReference nonExistingPropertyReference
                = new ValidatedPropertyReference("NonExistingProperty");
            rulesetData.Properties.Add(nonExistingPropertyReference);
            nonExistingPropertyReference.Validators.Add(new MockValidatorData("validator1", false));

            ConfigurationValidatedType validatedType
                = new ConfigurationValidatedType(rulesetData, typeof(ConfigurationValidatedTypeFixtureTestClass));
            IEnumerator<IValidatedElement> validatedPropertiesEnumerator
                = ((IValidatedType)validatedType).GetValidatedProperties().GetEnumerator();

            Assert.IsFalse(validatedPropertiesEnumerator.MoveNext());
        }
 public void UpdateFlyweight(ValidatedPropertyReference validatedPropertyReference, PropertyInfo propertyInfo)
 {
     UpdateFlyweight(validatedPropertyReference, propertyInfo, propertyInfo.PropertyType);
 }
예제 #11
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)
                    });
        }
        public void IterationContinuesAfterFlyweightUpdate()
        {
            ValidatedPropertyReference propertyReference = new ValidatedPropertyReference("Property");
            propertyReference.Validators.Add(new MockValidatorData("validator1", false));
            propertyReference.Validators.Get("validator1").MessageTemplate = "property validator 1 message";
            propertyReference.Validators.Add(new MockValidatorData("validator2", false));
            propertyReference.Validators.Get("validator2").MessageTemplate = "property validator 2 message";
            ValidatedFieldReference fieldReference = new ValidatedFieldReference("Field");
            fieldReference.Validators.Add(new MockValidatorData("validator1", false));
            fieldReference.Validators.Get("validator1").MessageTemplate = "field validator 1 message";
            fieldReference.Validators.Add(new MockValidatorData("validator2", false));
            fieldReference.Validators.Get("validator2").MessageTemplate = "field validator 2 message";
            fieldReference.Validators.Add(new MockValidatorData("validator3", false));
            fieldReference.Validators.Get("validator3").MessageTemplate = "field validator 3 message";

            ConfigurationValidatedElement validatedElement = new ConfigurationValidatedElement();
            PropertyInfo propertyInfo = typeof(ConfigurationValidatedElementFixtureTestClass).GetProperty("Property");
            FieldInfo fieldInfo = typeof(ConfigurationValidatedElementFixtureTestClass).GetField("Field");

            validatedElement.UpdateFlyweight(propertyReference, propertyInfo);
            Assert.AreSame(typeof(string), ((IValidatedElement)validatedElement).TargetType);
            IEnumerator<IValidatorDescriptor> propertyValidatorDescriptorsEnumerator
                = ((IValidatedElement)validatedElement).GetValidatorDescriptors().GetEnumerator();
            Assert.IsTrue(propertyValidatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("property validator 1 message",
                            ((MockValidatorData)propertyValidatorDescriptorsEnumerator.Current).MessageTemplate);

            validatedElement.UpdateFlyweight(fieldReference, fieldInfo);
            Assert.AreSame(typeof(int), ((IValidatedElement)validatedElement).TargetType);
            IEnumerator<IValidatorDescriptor> fieldValidatorDescriptorsEnumerator
                = ((IValidatedElement)validatedElement).GetValidatorDescriptors().GetEnumerator();
            Assert.IsTrue(fieldValidatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("field validator 1 message",
                            ((MockValidatorData)fieldValidatorDescriptorsEnumerator.Current).MessageTemplate);

            Assert.IsTrue(propertyValidatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("property validator 2 message",
                            ((MockValidatorData)propertyValidatorDescriptorsEnumerator.Current).MessageTemplate);
            Assert.IsTrue(fieldValidatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("field validator 2 message",
                            ((MockValidatorData)fieldValidatorDescriptorsEnumerator.Current).MessageTemplate);
            Assert.IsFalse(propertyValidatorDescriptorsEnumerator.MoveNext());
            Assert.IsTrue(fieldValidatorDescriptorsEnumerator.MoveNext());
            Assert.AreEqual("field validator 3 message",
                            ((MockValidatorData)fieldValidatorDescriptorsEnumerator.Current).MessageTemplate);
            Assert.IsFalse(fieldValidatorDescriptorsEnumerator.MoveNext());
        }
        public void CreateValidatorForRuleWithInvalidPropertyReferenceIgnoresInvalidProperty()
        {
            ValidationRulesetData ruleData = new ValidationRulesetData();
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("PublicProperty");
            ruleData.Properties.Add(propertyReference1);
            ValidatedPropertyReference propertyReference2 = new ValidatedPropertyReference("NonPublicProperty");
            ruleData.Properties.Add(propertyReference2);
            propertyReference1.Validators.Add(new MockValidatorData("validator1", false));
            propertyReference1.Validators.Get("validator1").MessageTemplate = "validator 1 message";
            propertyReference2.Validators.Add(new MockValidatorData("validator2", false));
            propertyReference2.Validators.Get("validator2").MessageTemplate = "validator 2 message";

            Validator validator = builder.CreateValidatorForRule(typeof(TestClass), ruleData);

            Assert.IsNotNull(validator);
            Assert.AreSame(typeof(ValueAccessValidator), validator.GetType());

            ValueAccessValidatorBuilder valueAccessValidatorBuilder1 = mockFactory.requestedMembers["TestClass.PublicProperty"];
            Assert.AreSame(valueAccessValidatorBuilder1.BuiltValidator, validator);
            Assert.AreEqual("validator 1 message", ((MockValidator<object>)valueAccessValidatorBuilder1.ValueValidators[0]).MessageTemplate);
        }
        public void CreateValidatorForRuleWithPropertyReferenceReturnsCompositeValidatorWithPropertyValueAccess()
        {
            ValidationRulesetData ruleData = new ValidationRulesetData();
            ValidatedPropertyReference propertyReference1 = new ValidatedPropertyReference("PublicProperty");
            ruleData.Properties.Add(propertyReference1);
            ValidatedPropertyReference propertyReference2 = new ValidatedPropertyReference("SecondPublicProperty");
            ruleData.Properties.Add(propertyReference2);
            propertyReference1.Validators.Add(new MockValidatorData("validator1", false));
            propertyReference1.Validators.Get("validator1").MessageTemplate = "validator 1 message";
            propertyReference2.Validators.Add(new MockValidatorData("validator2", false));
            propertyReference2.Validators.Get("validator2").MessageTemplate = "validator 2 message";

            Validator validator = builder.CreateValidatorForRule(typeof(TestClass), ruleData);

            Assert.IsNotNull(validator);
            Assert.AreSame(typeof(AndCompositeValidator), validator.GetType());
            IList<Validator> validators = ValidationTestHelper.CreateListFromEnumerable(((AndCompositeValidator)validator).Validators);
            Assert.AreEqual(2, validators.Count);
            Assert.AreEqual(2, mockFactory.requestedMembers.Count);
            ValueAccessValidatorBuilder valueAccessValidatorBuilder1 = mockFactory.requestedMembers["TestClass.PublicProperty"];
            Assert.AreSame(valueAccessValidatorBuilder1.BuiltValidator, validators[0]);
            Assert.AreEqual(1, valueAccessValidatorBuilder1.ValueValidators.Count);
            Assert.AreEqual("validator 1 message", ((MockValidator<object>)valueAccessValidatorBuilder1.ValueValidators[0]).MessageTemplate);
            ValueAccessValidatorBuilder valueAccessValidatorBuilder2 = mockFactory.requestedMembers["TestClass.SecondPublicProperty"];
            Assert.AreSame(valueAccessValidatorBuilder2.BuiltValidator, validators[1]);
            Assert.AreEqual(1, valueAccessValidatorBuilder2.ValueValidators.Count);
            Assert.AreEqual("validator 2 message", ((MockValidator<object>)valueAccessValidatorBuilder2.ValueValidators[0]).MessageTemplate);
        }
예제 #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <param name="propertyReference"></param>
        /// <returns></returns>
        public Validator CreateValidatorForProperty(Type type, ValidatedPropertyReference propertyReference)
        {
            if (propertyReference == null) throw new ArgumentNullException("propertyReference");

            if (propertyReference.Validators.Count == 0)
                return null;

            PropertyInfo propertyInfo = ValidationReflectionHelper.GetProperty(type, propertyReference.Name, false);
            if (propertyInfo == null)
                return null;

            ConfigurationValidatedElement validatedElement = new ConfigurationValidatedElement(propertyReference, propertyInfo);

            return CreateValidatorForValidatedElement(validatedElement, this.GetCompositeValidatorBuilderForProperty);
        }
        public void ValidatedPropertiesEnumerableSkipsPublicPropertyWithoutValidators()
        {
            ValidationRulesetData rulesetData = new ValidationRulesetData();
            ValidatedPropertyReference publicPropertyWithoutValidatorsReference
                = new ValidatedPropertyReference("PublicPropertyWithoutValidators");
            rulesetData.Properties.Add(publicPropertyWithoutValidatorsReference);

            ConfigurationValidatedType validatedType
                = new ConfigurationValidatedType(rulesetData, typeof(ConfigurationValidatedTypeFixtureTestClass));
            IEnumerator<IValidatedElement> validatedPropertiesEnumerator
                = ((IValidatedType)validatedType).GetValidatedProperties().GetEnumerator();

            Assert.IsFalse(validatedPropertiesEnumerator.MoveNext());
        }
예제 #17
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);
        }
        public void ValidatedPropertiesEnumerableIncludesPublicPropertyWithValidatorsOnly()
        {
            ValidationRulesetData rulesetData = new ValidationRulesetData();

            ValidatedPropertyReference nonExistingPropertyReference
                = new ValidatedPropertyReference("NonExistingProperty");
            rulesetData.Properties.Add(nonExistingPropertyReference);
            nonExistingPropertyReference.Validators.Add(new MockValidatorData("validator1", false));

            ValidatedPropertyReference publicPropertyWithoutValidatorsReference
                = new ValidatedPropertyReference("PublicPropertyWithoutValidators");
            rulesetData.Properties.Add(publicPropertyWithoutValidatorsReference);

            ValidatedPropertyReference writeOnlyPublicPropertyReference
                = new ValidatedPropertyReference("WriteOnlyPublicProperty");
            rulesetData.Properties.Add(writeOnlyPublicPropertyReference);
            writeOnlyPublicPropertyReference.Validators.Add(new MockValidatorData("validator1", false));

            ValidatedPropertyReference nonPublicPropertyReference
                = new ValidatedPropertyReference("NonPublicProperty");
            rulesetData.Properties.Add(nonPublicPropertyReference);
            nonPublicPropertyReference.Validators.Add(new MockValidatorData("validator1", false));

            ValidatedPropertyReference publicPropertyReference
                = new ValidatedPropertyReference("PublicProperty");
            rulesetData.Properties.Add(publicPropertyReference);
            publicPropertyReference.Validators.Add(new MockValidatorData("validator1", false));

            ValidatedPropertyReference secondPublicPropertyReference
                = new ValidatedPropertyReference("SecondPublicProperty");
            rulesetData.Properties.Add(secondPublicPropertyReference);
            secondPublicPropertyReference.Validators.Add(new MockValidatorData("validator1", false));

            ConfigurationValidatedType validatedType
                = new ConfigurationValidatedType(rulesetData, typeof(ConfigurationValidatedTypeFixtureTestClass));
            IEnumerator<IValidatedElement> validatedPropertiesEnumerator
                = ((IValidatedType)validatedType).GetValidatedProperties().GetEnumerator();

            Assert.IsTrue(validatedPropertiesEnumerator.MoveNext());
            Assert.AreSame(typeof(ConfigurationValidatedTypeFixtureTestClass).GetProperty("PublicProperty"),
                           validatedPropertiesEnumerator.Current.MemberInfo);
            Assert.IsTrue(validatedPropertiesEnumerator.MoveNext());
            Assert.AreSame(typeof(ConfigurationValidatedTypeFixtureTestClass).GetProperty("SecondPublicProperty"),
                           validatedPropertiesEnumerator.Current.MemberInfo);
            Assert.AreSame(typeof(string), validatedPropertiesEnumerator.Current.TargetType);

            Assert.IsFalse(validatedPropertiesEnumerator.MoveNext());
        }
        public void CanDeserializeSerializedSectionWithNamedRuleSpecifyingMultipleValidatorsForProperty()
        {
            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);
            ValidatedPropertyReference rwValidationPropertyReference = new ValidatedPropertyReference("System.String.Length");
            rwValidationRule.Properties.Add(rwValidationPropertyReference);
            ValidatorData rwPropertyValidatorData1 = new MockValidatorData("ruleset-validator1", false);
            rwValidationPropertyReference.Validators.Add(rwPropertyValidatorData1);
            ValidatorData rwPropertyValidatorData2 = new MockValidatorData("ruleset-validator2", false);
            rwValidationPropertyReference.Validators.Add(rwPropertyValidatorData2);

            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).Properties.Count);
                Assert.AreEqual("System.String.Length", roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Name);
                Assert.AreEqual(2, roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Count);
                Assert.AreEqual("ruleset-validator1", roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Get(0).Name);
                Assert.AreSame(typeof(MockValidatorData), roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Get(0).GetType());
                Assert.AreEqual(false, ((MockValidatorData)roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Get(0)).ReturnFailure);
                Assert.AreEqual("ruleset-validator2", roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Get(1).Name);
                Assert.AreSame(typeof(MockValidatorData), roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Get(1).GetType());
                Assert.AreEqual(false, ((MockValidatorData)roSettings.Types.Get(0).Rulesets.Get(0).Properties.Get(0).Validators.Get(1)).ReturnFailure);
            }
        }
        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);
        }