public void ExecuteCommand(ValidationCommandContext context)
        {
            bool   condition    = Condition.Invoke();
            object value        = RequiredProperty.Compile().Invoke();
            var    propertyName = RequiredProperty.GetPropertyName();

            if (value == null && condition)
            {
                context.AddError(new ValidationResult(ErrorMessage, new[] { propertyName }));
            }
        }
        public void PropertyValidatorValidateTests()
        {
            var testObject = new TestObject();

            var validator = new RequiredProperty();

            Assert.IsFalse(validator.IsValid(null));
            Assert.IsFalse(validator.IsValid("  "));
            Assert.IsTrue(validator.IsValid("Somthing"));

            Assert.IsNotNull(validator.GetErrorMessage("RequiredProperty"));
        }
Exemple #3
0
 void Ex13()
 {
     When("the property validation is enabled", () => RequiredProperty.EnableValidation(() => RequiredProperty));
     When("the property validation is ensured", () => RequiredProperty.EnsureValidation());
     AssertValidationError(RequiredProperty, "Please enter a value.");
 }