public void Validate() { Page page = new TestPage(HttpContext.Current); IValidator[] validators = new IValidator[] {new RequiredValidator("Name", null), new ConditionValidator("Loan == 0", "Age > 21")}; Contact contact = new Contact("Goran", 24, 0); bool result = page.Validate(contact, validators); Assert.IsTrue(result); contact = new Contact(null, 24, 0); result = page.Validate(contact, validators); Assert.IsFalse(result); contact = new Contact("Goran", 24, 1); result = page.Validate(contact, validators); Assert.IsFalse(result); }
public void ErrorTests() { const string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'> <object id='ccAmex' type='Spring.Validation.Validators.Amex, Spring.Core'/> <v:validator id='ccValidator' test='Creditcard' type='Spring.Validation.Validators.CreditCardValidator, Spring.Core'> <v:property name='CardType' ref='ccAmex'/> <v:message id='errorKey' providers='validationSummary' /> </v:validator> </objects>"; MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml)); IResource resource = new InputStreamResource(stream, "ccValidator"); XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null); IValidationErrors errors = new ValidationErrors(); Contact contact = new Contact(); IValidator validator = (IValidator)objectFactory.GetObject("ccValidator"); contact.Creditcard = "378282246310"; bool result = validator.Validate(contact, errors); Assert.IsNotNull(errors.GetErrors("validationSummary")); Assert.IsFalse(result); }