public void Validate() { CreditCardValidator validator = new CreditCardValidator(); validator.CardType = new Amex(); Assert.IsTrue(validator.Validate("378282246310005", new ValidationErrors())); Assert.IsFalse(validator.Validate("444444444", new ValidationErrors())); Assert.IsTrue(validator.Validate(" ", new ValidationErrors())); Assert.IsTrue(validator.Validate("", new ValidationErrors())); Assert.IsTrue(validator.Validate(null, new ValidationErrors())); }
public void WithNullCardType() { const string xml = @"<?xml version='1.0' encoding='UTF-8' ?> <objects xmlns='http://www.springframework.net' xmlns:v='http://www.springframework.net/validation'> <v:validator id='ccValidator' test='#this' type='Spring.Validation.Validators.CreditCardValidator, Spring.Core'> <v:message id='error.airportCode.dummy' providers='summary' when='false'/> </v:validator> </objects>"; MemoryStream stream = new MemoryStream(new UTF8Encoding().GetBytes(xml)); IResource resource = new InputStreamResource(stream, "ccValidator"); XmlObjectFactory objectFactory = new XmlObjectFactory(resource, null); object obj = objectFactory.GetObject("ccValidator"); Assert.IsTrue(obj is CreditCardValidator); CreditCardValidator validator = obj as CreditCardValidator; Assert.IsNull(validator.CardType); Assert.IsTrue(validator.Validate("378282246310005", new ValidationErrors())); }