public void CanDeserializeSerializedInstanceWithChildValidators() { MockValidationSettings rwSettings = new MockValidationSettings(); AndCompositeValidatorData rwValidatorData = new AndCompositeValidatorData("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(AndCompositeValidatorData), roSettings.Validators.Get(0).GetType()); Assert.AreEqual(2, ((AndCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Count); Assert.AreEqual("child validator 1", ((AndCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Get(0).Name); Assert.AreEqual("child validator 2", ((AndCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Get(1).Name); } }
public void CanCreateValidatorFromEmptyConfigurationObject() { AndCompositeValidatorData rwValidatorData = new AndCompositeValidatorData("validator1"); Validator validator = ((IValidatorDescriptor)rwValidatorData).CreateValidator(null, null, null); Assert.IsNotNull(validator); Assert.AreSame(typeof(AndCompositeValidator), validator.GetType()); IList <Validator> validators = ValidationTestHelper.CreateListFromEnumerable <Validator>(((AndCompositeValidator)validator).Validators); Assert.AreEqual(0, validators.Count); }
/// <summary> /// Returns the runtime configuration data that is represented by this node. /// </summary> /// <returns>An instance of <see cref="AndCompositeValidatorData"/> that can be persisted to a configuration file.</returns> public override ValidatorData CreateValidatorData() { AndCompositeValidatorData validatorData = new AndCompositeValidatorData(Name); foreach (ConfigurationNode childNode in Nodes) { ValidatorNodeBase validatorNode = childNode as ValidatorNodeBase; if (validatorNode != null) { validatorData.Validators.Add(validatorNode.CreateValidatorData()); } } return(validatorData); }
/// <summary> /// Returns the runtime configuration data that is represented by this node. /// </summary> /// <returns>An instance of <see cref="AndCompositeValidatorData"/> that can be persisted to a configuration file.</returns> public override ValidatorData CreateValidatorData() { AndCompositeValidatorData validatorData = new AndCompositeValidatorData(Name); foreach (ConfigurationNode childNode in Nodes) { ValidatorNodeBase validatorNode = childNode as ValidatorNodeBase; if (validatorNode != null) { validatorData.Validators.Add(validatorNode.CreateValidatorData()); } } return validatorData; }
public void CanCreateValidatorFromConfigurationObject() { AndCompositeValidatorData rwValidatorData = new AndCompositeValidatorData("validator1"); rwValidatorData.Validators.Add(new MockValidatorData("child validator 1", false)); rwValidatorData.Validators.Get(0).MessageTemplate = "child validator 1"; rwValidatorData.Validators.Add(new MockValidatorData("child validator 2", false)); rwValidatorData.Validators.Get(1).MessageTemplate = "child validator 2"; Validator validator = ((IValidatorDescriptor)rwValidatorData).CreateValidator(null, null, null); Assert.IsNotNull(validator); Assert.AreSame(typeof(AndCompositeValidator), validator.GetType()); IList <Validator> validators = ValidationTestHelper.CreateListFromEnumerable <Validator>(((AndCompositeValidator)validator).Validators); Assert.AreEqual(2, validators.Count); Assert.AreEqual("child validator 1", ((MockValidator <object>)validators[0]).MessageTemplate); Assert.AreEqual("child validator 2", ((MockValidator <object>)validators[1]).MessageTemplate); }
/// <summary> /// Creates an instance of <see cref="AndCompositeValidatorNode"/> based on runtime configuration data. /// </summary> /// <param name="validatorData">The corresponding runtime configuration data.</param> public AndCompositeValidatorNode(AndCompositeValidatorData validatorData) : base(validatorData.Name) { }