Ejemplo n.º 1
0
        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()));
        }
Ejemplo n.º 2
0
        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='Oragon.Spring.Validation.Validators.CreditCardValidator, Oragon.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.Throws <ArgumentException>(() => validator.Validate("378282246310005", new ValidationErrors()));
        }