public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            TypeConversionValidatorData rwValidatorData = new TypeConversionValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Negated = true;
            rwValidatorData.TargetType = typeof(double);

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(TypeConversionValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(true, ((TypeConversionValidatorData)roSettings.Validators.Get(0)).Negated);
                Assert.AreEqual(typeof(double), ((TypeConversionValidatorData)roSettings.Validators.Get(0)).TargetType);
            }
        }
        public void CanDeserializeSerializedInstanceWithNameOnly()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            DateTimeRangeValidatorData rwValidatorData = new DateTimeRangeValidatorData("validator1");
            rwSettings.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;

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(DateTimeRangeValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(default(DateTime), ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).LowerBound);
                Assert.AreEqual(RangeBoundaryType.Ignore, ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).LowerBoundType);
                Assert.AreEqual(default(DateTime), ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).UpperBound);
                Assert.AreEqual(RangeBoundaryType.Inclusive, ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).UpperBoundType);
            }
        }
        public void CanDeserializeSerializedInstanceWithChildValidators()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            OrCompositeValidatorData rwValidatorData = new OrCompositeValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Validators.Add(new MockValidatorData("child validator 1", false));
            rwValidatorData.Validators.Add(new MockValidatorData("child validator 2", false));

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(OrCompositeValidatorData), roSettings.Validators.Get(0).GetType());
                Assert.AreEqual(2, ((OrCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Count);
                Assert.AreEqual("child validator 1", ((OrCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Get(0).Name);
                Assert.AreEqual("child validator 2", ((OrCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Get(1).Name);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            StringLengthValidatorData rwValidatorData = new StringLengthValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.LowerBound = 10;
            rwValidatorData.LowerBoundType = RangeBoundaryType.Exclusive;
            rwValidatorData.UpperBound = 20;
            rwValidatorData.UpperBoundType = RangeBoundaryType.Inclusive;

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(StringLengthValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(10, ((StringLengthValidatorData)roSettings.Validators.Get(0)).LowerBound);
                Assert.AreEqual(RangeBoundaryType.Exclusive, ((StringLengthValidatorData)roSettings.Validators.Get(0)).LowerBoundType);
                Assert.AreEqual(20, ((StringLengthValidatorData)roSettings.Validators.Get(0)).UpperBound);
                Assert.AreEqual(RangeBoundaryType.Inclusive, ((StringLengthValidatorData)roSettings.Validators.Get(0)).UpperBoundType);
                Assert.AreEqual(false, ((StringLengthValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            PropertyComparisonValidatorData rwValidatorData = new PropertyComparisonValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.ComparisonOperator = ComparisonOperator.GreaterThanEqual;
            rwValidatorData.PropertyToCompare = "property";
            rwValidatorData.Negated = true;

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(PropertyComparisonValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(ComparisonOperator.GreaterThanEqual, ((PropertyComparisonValidatorData)roSettings.Validators.Get(0)).ComparisonOperator);
                Assert.AreEqual("property", ((PropertyComparisonValidatorData)roSettings.Validators.Get(0)).PropertyToCompare);
                Assert.AreEqual(true, ((PropertyComparisonValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            RangeValidatorData rwValidatorData = new RangeValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Negated = true;
            rwValidatorData.Culture = CultureInfo.GetCultureInfo("nl-NL");
            rwValidatorData.LowerBound = "12";
            rwValidatorData.LowerBoundType = RangeBoundaryType.Exclusive;
            rwValidatorData.UpperBound = "24";
            rwValidatorData.UpperBoundType = RangeBoundaryType.Inclusive;

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(RangeValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(true, ((RangeValidatorData)roSettings.Validators.Get(0)).Negated);
                Assert.AreEqual("12", ((RangeValidatorData)roSettings.Validators.Get(0)).LowerBound);
                Assert.AreEqual(RangeBoundaryType.Exclusive, ((RangeValidatorData)roSettings.Validators.Get(0)).LowerBoundType);
                Assert.AreEqual("24", ((RangeValidatorData)roSettings.Validators.Get(0)).UpperBound);
                Assert.AreEqual(RangeBoundaryType.Inclusive, ((RangeValidatorData)roSettings.Validators.Get(0)).UpperBoundType);
                Assert.AreEqual(CultureInfo.GetCultureInfo("nl-NL"), rwValidatorData.Culture);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            DomainValidatorData rwValidatorData = new DomainValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Negated = true;
            rwValidatorData.Domain.Add(new DomainConfigurationElement("1"));
            rwValidatorData.Domain.Add(new DomainConfigurationElement("2"));
            rwValidatorData.Domain.Add(new DomainConfigurationElement("3"));

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(DomainValidator<object>), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(true, ((DomainValidatorData)roSettings.Validators.Get(0)).Negated);
                Assert.AreEqual(3, ((DomainValidatorData)roSettings.Validators.Get(0)).Domain.Count);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            CustomValidatorData rwValidatorData = new CustomValidatorData("validator1", typeof(MockCustomValidator));
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Attributes.Add("returnFailure", "true");
            rwValidatorData.Attributes.Add("foo", "bar");

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(MockCustomValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(2, ((CustomValidatorData)roSettings.Validators.Get(0)).Attributes.Count);
                Assert.AreEqual("true", ((CustomValidatorData)roSettings.Validators.Get(0)).Attributes["returnFailure"]);
                Assert.AreEqual("bar", ((CustomValidatorData)roSettings.Validators.Get(0)).Attributes["foo"]);
            }
        }
        public void CanDeserializeSerializedInstanceWithNameTargetTypeAndTargetRuleset()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            ObjectCollectionValidatorData rwValidatorData = new ObjectCollectionValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.TargetType = typeof(ObjectCollectionValidatorDataFixture);
            rwValidatorData.TargetRuleset = "ruleset";

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(ObjectCollectionValidator), roSettings.Validators.Get(0).Type);
                Assert.AreSame(typeof(ObjectCollectionValidatorDataFixture), ((ObjectCollectionValidatorData)roSettings.Validators.Get(0)).TargetType);
                Assert.AreEqual("ruleset", ((ObjectCollectionValidatorData)roSettings.Validators.Get(0)).TargetRuleset);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            ContainsCharactersValidatorData rwValidatorData = new ContainsCharactersValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.CharacterSet = "abc";
            rwValidatorData.ContainsCharacters = ContainsCharacters.All;

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(ContainsCharactersValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("abc", ((ContainsCharactersValidatorData)roSettings.Validators.Get(0)).CharacterSet);
                Assert.AreEqual(ContainsCharacters.All, ((ContainsCharactersValidatorData)roSettings.Validators.Get(0)).ContainsCharacters);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            RelativeDateTimeValidatorData rwValidatorData = new RelativeDateTimeValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Negated = true;
            rwValidatorData.LowerBound = 2;
            rwValidatorData.LowerBoundType = RangeBoundaryType.Exclusive;
            rwValidatorData.LowerUnit = DateTimeUnit.Year;
            rwValidatorData.UpperBound = 3;
            rwValidatorData.UpperBoundType = RangeBoundaryType.Ignore;
            rwValidatorData.UpperUnit = DateTimeUnit.Month;

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(RelativeDateTimeValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(true, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).Negated);
                Assert.AreEqual(2, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).LowerBound);
                Assert.AreEqual(RangeBoundaryType.Exclusive, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).LowerBoundType);
                Assert.AreEqual(DateTimeUnit.Year, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).LowerUnit);
                Assert.AreEqual(3, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).UpperBound);
                Assert.AreEqual(RangeBoundaryType.Ignore, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).UpperBoundType);
                Assert.AreEqual(DateTimeUnit.Month, ((RelativeDateTimeValidatorData)roSettings.Validators.Get(0)).UpperUnit);
            }
        }
        public void CanDeserializeSerializedInstanceWithNameAndTypeAndMessageTemplate()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            ValidatorData rwValidatorData = new MockValidatorData("validator1", false);
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.MessageTemplate = "message template";

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(MockValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("message template", roSettings.Validators.Get(0).MessageTemplate);
                Assert.AreEqual(string.Empty, roSettings.Validators.Get(0).MessageTemplateResourceName);
                Assert.AreEqual(string.Empty, roSettings.Validators.Get(0).MessageTemplateResourceTypeName);
                Assert.AreEqual(string.Empty, roSettings.Validators.Get(0).Tag);
            }
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            RegexValidatorData rwValidatorData = new RegexValidatorData("validator1");
            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Pattern = "pattern";
            rwValidatorData.PatternResourceName = RegexResourceName1;
            rwValidatorData.PatternResourceType = typeof(Resources);
            rwValidatorData.Negated = true;
            rwValidatorData.Options = RegexOptions.Multiline | RegexOptions.IgnoreCase;

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

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

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(RegexValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("pattern", ((RegexValidatorData)roSettings.Validators.Get(0)).Pattern);
                Assert.AreEqual(RegexResourceName1, ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceName);
                Assert.AreEqual(typeof(Resources), ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceType);
                Assert.AreEqual(RegexOptions.Multiline | RegexOptions.IgnoreCase, ((RegexValidatorData)roSettings.Validators.Get(0)).Options);
                Assert.AreEqual(true, ((RegexValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
        public void CanDeserializeSerializedInstanceWithNameOnly()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            RegexValidatorData rwValidatorData = new RegexValidatorData("validator1");
            rwSettings.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;

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(RegexValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("", ((RegexValidatorData)roSettings.Validators.Get(0)).Pattern);
                Assert.AreEqual("", ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceName);
                Assert.AreEqual(null, ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceType);
                Assert.AreEqual(RegexOptions.None, ((RegexValidatorData)roSettings.Validators.Get(0)).Options);
                Assert.AreEqual(false, ((RegexValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
        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);
            }
        }
        public void CanDeserializeSerializedInstance()
        {
            MockValidationSettings rwSettings = new MockValidationSettings();
            ValidatorData rwValidatorData = new NotNullValidatorData("validator1");
            rwSettings.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;

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

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(NotNullValidator), roSettings.Validators.Get(0).Type);
            }
        }
        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);
            }
        }