public void CanDeserializeSerializedInstanceWithValuesSet() { MockValidationSettings rwSettings = new MockValidationSettings(); EnumConversionValidatorData rwValidatorData = new EnumConversionValidatorData("validator1"); rwSettings.Validators.Add(rwValidatorData); rwValidatorData.Negated = true; rwValidatorData.EnumType = typeof(MockEnumValidator); 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(EnumConversionValidator), roSettings.Validators.Get(0).Type); Assert.AreEqual(true, ((EnumConversionValidatorData)roSettings.Validators.Get(0)).Negated); Assert.AreEqual(typeof(MockEnumValidator), ((EnumConversionValidatorData)roSettings.Validators.Get(0)).EnumType); } }
/// <summary> /// Returns the runtime configuration data that is represented by this node. /// </summary> /// <returns>An instance of <see cref="EnumConversionValidatorData"/> that can be persisted to a configuration file.</returns> public override ValidatorData CreateValidatorData() { EnumConversionValidatorData validatorData = new EnumConversionValidatorData(Name); SetValidatorBaseProperties(validatorData); SetValueValidatorBaseProperties(validatorData); validatorData.EnumTypeName = enumTypeName; return(validatorData); }
public void CreatedNodeWithValidatorDataHasAppropriateValuesFromData() { EnumConversionValidatorData validatorData = new EnumConversionValidatorData("name"); validatorData.Negated = true; validatorData.EnumType = typeof(MockEnumValidator); EnumConversionValidatorNode node = new EnumConversionValidatorNode(validatorData); Assert.AreEqual("name", node.Name); Assert.AreEqual(true, node.Negated); Assert.AreEqual(validatorData.EnumTypeName, node.EnumType); }
public void NodeCreatesValidatorDataWithValues() { EnumConversionValidatorNode node = new EnumConversionValidatorNode(); node.Name = "validator"; node.Negated = true; node.EnumType = typeof(MockEnumValidator).AssemblyQualifiedName; EnumConversionValidatorData validatorData = node.CreateValidatorData() as EnumConversionValidatorData; Assert.IsNotNull(validatorData); Assert.AreEqual("validator", validatorData.Name); Assert.AreEqual(true, validatorData.Negated); Assert.AreEqual(typeof(MockEnumValidator), validatorData.EnumType); }
public void CreatedNodeHasAppropriateDefaultValues() { EnumConversionValidatorNode node = new EnumConversionValidatorNode(); EnumConversionValidatorData validatorData = node.CreateValidatorData() as EnumConversionValidatorData; Assert.IsNotNull(validatorData); Assert.AreEqual(Resources.EnumConversionValidatorNodeName, validatorData.Name); Assert.AreEqual(false, validatorData.Negated); Assert.IsNull(validatorData.EnumType); Assert.AreEqual(Resources.EnumConversionValidatorNodeName, node.Name); Assert.AreEqual(false, node.Negated); Assert.AreEqual(string.Empty, node.EnumType); }
public void CanCreateValidatorFromConfigurationObject() { EnumConversionValidatorData rwValidatorData = new EnumConversionValidatorData("validator1"); rwValidatorData.Negated = true; rwValidatorData.EnumType = typeof(MockEnumValidator); Validator validator = ((IValidatorDescriptor)rwValidatorData).CreateValidator(null, null, null, null); Assert.IsNotNull(validator); Assert.AreSame(typeof(EnumConversionValidator), validator.GetType()); Assert.AreEqual(Resources.EnumConversionNegatedDefaultMessageTemplate, validator.MessageTemplate); Assert.AreEqual(true, ((EnumConversionValidator)validator).Negated); Assert.AreEqual(typeof(MockEnumValidator), ((EnumConversionValidator)validator).EnumType); }
/// <summary> /// Creates an instance of <see cref="EnumConversionValidatorNode"/> based on runtime configuration data. /// </summary> /// <param name="validatorData">The corresponding runtime configuration data.</param> public EnumConversionValidatorNode(EnumConversionValidatorData validatorData) : base(validatorData) { enumTypeName = validatorData.EnumTypeName; }
/// <summary> /// Returns the runtime configuration data that is represented by this node. /// </summary> /// <returns>An instance of <see cref="EnumConversionValidatorData"/> that can be persisted to a configuration file.</returns> public override ValidatorData CreateValidatorData() { EnumConversionValidatorData validatorData = new EnumConversionValidatorData(Name); SetValidatorBaseProperties(validatorData); SetValueValidatorBaseProperties(validatorData); validatorData.EnumTypeName = enumTypeName; return validatorData; }
/// <summary> /// Creates an instance of <see cref="EnumConversionValidatorNode"/> based on runtime configuration data. /// </summary> /// <param name="validatorData">The corresponding runtime configuration data.</param> public EnumConversionValidatorNode(EnumConversionValidatorData validatorData) : base(validatorData) { enumTypeName = validatorData.EnumTypeName; }