/// <summary> /// Compiles the mapping of component configuration properties to <see cref="PropertyValidator"/> objects as described by the specified component. /// </summary> /// <param name="component">The component to check whether it has defined validators for a configuration property.</param> private void CompileExternalValidatorMapping(GeneticComponent component) { if (component == null) { return; } IExternalConfigurationPropertyValidatorAttribute[] attribs = (IExternalConfigurationPropertyValidatorAttribute[])component.GetType().GetCustomAttributes(typeof(IExternalConfigurationPropertyValidatorAttribute), true); foreach (IExternalConfigurationPropertyValidatorAttribute attrib in attribs) { PropertyInfo prop = ExternalValidatorAttributeHelper.GetTargetPropertyInfo(attrib.TargetComponentType, attrib.TargetPropertyName); if (!this.externalValidationMapping.TryGetValue(prop, out List <PropertyValidator> validators)) { validators = new List <PropertyValidator>(); this.externalValidationMapping.Add(prop, validators); } validators.Add(attrib.Validator); } }
public void ExternalValidatorAttributeHelper_ValidateArgs_InvalidTargetProperty() { Assert.Throws <ArgumentException>(() => ExternalValidatorAttributeHelper.ValidateArguments(typeof(FakeComponent), "boo")); }
public void ExternalValidatorAttributeHelper_ValidateArgs_InvalidTargetType() { Assert.Throws <ArgumentException>(() => ExternalValidatorAttributeHelper.ValidateArguments(typeof(InvalidComponent), "Value")); }
public void ExternalValidatorAttributeHelper_ValidateArgs_NullTargetType() { Assert.Throws <ArgumentNullException>(() => ExternalValidatorAttributeHelper.ValidateArguments(null, "c")); }