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); } }
/// <summary> /// Creates an instance of <see cref="OrCompositeValidatorNode"/> based on runtime configuration data. /// </summary> /// <param name="validatorData">The corresponding runtime configuration data.</param> public OrCompositeValidatorNode(OrCompositeValidatorData validatorData) : base(validatorData.Name) { messageTemplate = validatorData.MessageTemplate; messageTemplateResourceName = validatorData.MessageTemplateResourceName; messageTemplateResourceTypeName = validatorData.MessageTemplateResourceTypeName; tag = validatorData.Tag; }
public void CanCreateValidatorFromEmptyConfigurationObject() { OrCompositeValidatorData rwValidatorData = new OrCompositeValidatorData("validator1"); Validator validator = ((IValidatorDescriptor)rwValidatorData).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); Assert.AreSame(typeof(OrCompositeValidator), validator.GetType()); IList <Validator> validators = ValidationTestHelper.CreateListFromEnumerable <Validator>(((OrCompositeValidator)validator).Validators); Assert.AreEqual(0, validators.Count); }
public void CanCreateValidatorFromConfigurationObject() { OrCompositeValidatorData rwValidatorData = new OrCompositeValidatorData("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, null); Assert.IsNotNull(validator); Assert.AreSame(typeof(OrCompositeValidator), validator.GetType()); IList <Validator> validators = ValidationTestHelper.CreateListFromEnumerable <Validator>(((OrCompositeValidator)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> /// Returns the runtime configuration data that is represented by this node. /// </summary> /// <returns>An instance of <see cref="OrCompositeValidatorData"/> that can be persisted to a configuration file.</returns> public override ValidatorData CreateValidatorData() { OrCompositeValidatorData validatorData = new OrCompositeValidatorData(Name); validatorData.MessageTemplate = messageTemplate; validatorData.MessageTemplateResourceName = messageTemplateResourceName; validatorData.MessageTemplateResourceTypeName = messageTemplateResourceTypeName; validatorData.Tag = tag; 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="OrCompositeValidatorData"/> that can be persisted to a configuration file.</returns> public override ValidatorData CreateValidatorData() { OrCompositeValidatorData validatorData = new OrCompositeValidatorData(Name); validatorData.MessageTemplate = messageTemplate; validatorData.MessageTemplateResourceName = messageTemplateResourceName; validatorData.MessageTemplateResourceTypeName = messageTemplateResourceTypeName; validatorData.Tag = tag; foreach (ConfigurationNode childNode in Nodes) { ValidatorNodeBase validatorNode = childNode as ValidatorNodeBase; if (validatorNode != null) { validatorData.Validators.Add(validatorNode.CreateValidatorData()); } } return validatorData; }