public void AttributeValidation_DoNotValidate() { var instance = new ObjectWithValidation(); instance.SetValue(ObjectWithValidation.ValueWithAnnotationsProperty.Name, string.Empty, true, false); var fieldValidations = instance.ValidationContext.GetFieldValidations(ObjectWithValidation.ValueWithAnnotationsProperty.Name); Assert.AreEqual(0, fieldValidations.Count); instance.SetValue(ObjectWithValidation.ValueWithAnnotationsProperty.Name, null, true, true); fieldValidations = instance.ValidationContext.GetFieldValidations(ObjectWithValidation.ValueWithAnnotationsProperty.Name); Assert.AreEqual(1, fieldValidations.Count); }
public void ValidationUsingAnnotationsForCatelProperties() { var validationObject = new ObjectWithValidation(); Assert.IsFalse(validationObject.HasErrors); validationObject.ValueWithAnnotations = string.Empty; Assert.IsTrue(validationObject.HasErrors); validationObject.ValueWithAnnotations = "value"; Assert.IsFalse(validationObject.HasErrors); }
public void ValidationWithWarnings() { var validationObject = new ObjectWithValidation(); var validation = validationObject as IModelValidation; // Check if the object now has warnings Assert.AreEqual(false, validation.HasWarnings); Assert.AreEqual(false, validation.HasErrors); Assert.AreEqual(0, validation.FieldWarningCount); Assert.AreEqual(0, validation.FieldErrorCount); Assert.AreEqual(0, validation.BusinessRuleWarningCount); Assert.AreEqual(0, validation.BusinessRuleErrorCount); // Now set a field warning and check it validationObject.ValueToValidate = ObjectWithValidation.ValueThatCausesFieldWarning; Assert.AreEqual(true, validation.HasWarnings); Assert.AreEqual(false, validation.HasErrors); Assert.AreEqual(1, validation.FieldWarningCount); Assert.AreEqual(0, validation.FieldErrorCount); Assert.AreEqual(0, validation.BusinessRuleWarningCount); Assert.AreEqual(0, validation.BusinessRuleErrorCount); // Now set a business warning and check it validationObject.ValueToValidate = ObjectWithValidation.ValueThatCausesBusinessWarning; Assert.AreEqual(true, validation.HasWarnings); Assert.AreEqual(false, validation.HasErrors); Assert.AreEqual(0, validation.FieldWarningCount); Assert.AreEqual(0, validation.FieldErrorCount); Assert.AreEqual(1, validation.BusinessRuleWarningCount); Assert.AreEqual(0, validation.BusinessRuleErrorCount); // Clear warning validationObject.ValueToValidate = ObjectWithValidation.ValueThatHasNoWarningsOrErrors; Assert.AreEqual(false, validation.HasWarnings); Assert.AreEqual(false, validation.HasErrors); Assert.AreEqual(0, validation.FieldWarningCount); Assert.AreEqual(0, validation.FieldErrorCount); Assert.AreEqual(0, validation.BusinessRuleWarningCount); Assert.AreEqual(0, validation.BusinessRuleErrorCount); }
public void ValidationUsingAnnotationsForNonCatelCalculatedProperties() { var validationObject = new ObjectWithValidation(); Assert.IsFalse(validationObject.HasErrors); }