public void AttributeWithInvalidPropertyNameThrowsWhenCreatingValidator() { MemberValueAccessBuilder builder = new ReflectionMemberValueAccessBuilder(); IValidatorDescriptor validatorAttribute = new PropertyComparisonValidatorAttribute("InvalidProperty", ComparisonOperator.Equal); validatorAttribute.CreateValidator(typeof(PropertyComparisonValidatorAttributeFixtureTestClass), typeof(PropertyComparisonValidatorAttributeFixtureTestClass), builder, null); }
public void AttributeWithNullRulesetCannotBeUsedAsValidationAttribute() { ValidationAttribute attribute = new PropertyComparisonValidatorAttribute("proeprty", ComparisonOperator.NotEqual); try { attribute.IsValid(""); Assert.Fail("should have thrown"); } catch (NotSupportedException) { } }
public void CreatesAppropriateValidator() { MemberValueAccessBuilder builder = new ReflectionMemberValueAccessBuilder(); PropertyComparisonValidatorAttribute validatorAttribute = new PropertyComparisonValidatorAttribute("PublicProperty", ComparisonOperator.NotEqual); validatorAttribute.Negated = true; PropertyComparisonValidator validator = ((IValidatorDescriptor)validatorAttribute).CreateValidator(typeof(PropertyComparisonValidatorAttributeFixtureTestClass), typeof(PropertyComparisonValidatorAttributeFixtureTestClass), builder, 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); }
public void AttributeWithNonNullRulesetReturnsValid() { ValidationAttribute attribute = new PropertyComparisonValidatorAttribute("proeprty", ComparisonOperator.NotEqual) { Ruleset = "ruleset" }; Assert.IsTrue(attribute.IsValid("")); }