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 CreateValidatorWithNoPropertyThrows() { PropertyComparisonValidatorData rwValidatorData = new PropertyComparisonValidatorData("validator1"); ((IValidatorDescriptor)rwValidatorData).CreateValidator(typeof(string), typeof(PropertyComparisonValidatorDataFixtureTestClass), new ReflectionMemberValueAccessBuilder(), null); }
public void CreateValidatorWithInvalidPropertyThrows() { PropertyComparisonValidatorData rwValidatorData = new PropertyComparisonValidatorData("validator1"); rwValidatorData.PropertyToCompare = "Property"; PropertyComparisonValidator validator = ((IValidatorDescriptor)rwValidatorData).CreateValidator(typeof(string), typeof(PropertyComparisonValidatorDataFixtureTestClass), new ReflectionMemberValueAccessBuilder(), null) as PropertyComparisonValidator; Assert.IsNotNull(validator); Assert.AreEqual("PublicProperty", ((PropertyValueAccess)validator.ValueAccess).PropertyInfo.Name); Assert.AreEqual(ComparisonOperator.NotEqual, validator.ComparisonOperator); Assert.AreEqual(true, validator.Negated); }