public void IsValid()
        {
            var sla = new CreditCardAttribute();

            Assert.IsTrue(sla.IsValid(null), "#A1-1");
            Assert.IsTrue(sla.IsValid(String.Empty), "#A1-2");
            Assert.IsFalse(sla.IsValid("string"), "#A1-3");
            Assert.IsTrue(sla.IsValid("378282246310005"), "#A1-4");
            Assert.IsTrue(sla.IsValid("3782-8224-6310-005"), "#A1-5");
            Assert.IsTrue(sla.IsValid("371449635398431"), "#A-6");
            Assert.IsFalse(sla.IsValid("371449635498431"), "#A-6b");
            Assert.IsFalse(sla.IsValid(true), "#A1-7");
            Assert.IsFalse(sla.IsValid(DateTime.Now), "#A1-8");
        }
Exemplo n.º 2
0
        public void IsValidTests()
        {
            // Arrange
            var attribute = new CreditCardAttribute();

            // Act & Assert
            Assert.True(attribute.IsValid(null));                  // Optional values are always valid
            Assert.True(attribute.IsValid("0000000000000000"));    // Simplest valid value
            Assert.True(attribute.IsValid("1234567890123452"));    // Good checksum
            Assert.True(attribute.IsValid("1234-5678-9012-3452")); // Good checksum, with dashes
            Assert.False(attribute.IsValid("0000000000000001"));   // Bad checksum
            Assert.False(attribute.IsValid(0));                    // Non-string
            Assert.False(attribute.IsValid("000%000000000001"));   // Non-digit
        }
        public void IsValidTests()
        {
            // Arrange
            var attribute = new CreditCardAttribute();

            // Act & Assert
            Assert.True(attribute.IsValid(null)); // Optional values are always valid
            Assert.True(attribute.IsValid("0000000000000000")); // Simplest valid value
            Assert.True(attribute.IsValid("1234567890123452")); // Good checksum
            Assert.True(attribute.IsValid("1234-5678-9012-3452")); // Good checksum, with dashes
            Assert.False(attribute.IsValid("0000000000000001")); // Bad checksum
            Assert.False(attribute.IsValid(0)); // Non-string
            Assert.False(attribute.IsValid("000%000000000001")); // Non-digit
        }
Exemplo n.º 4
0
        protected void btnApoiar_Click(object sender, EventArgs e)
        {
            CreditCardAttribute valida = new CreditCardAttribute();

            try
            {
                decimal valor = 0m;
                if (projeto.tipo.TrimEnd() == "Doação")
                {
                    string cartao = txtCartaoCredito.Text;
                    valor = Convert.ToDecimal(txtValor.Text);
                    //ESTOU SEM NET ENTÃO VOU DEIXAR PASSAR PARA FIM DE TESTES, MAS DEPOIS MUDAR PARA !valida.IsValid(txtCartaoCredito.Text)
                    if (valida.IsValid(txtCartaoCredito.Text))
                    {
                        lblErro.Text    = "Cartão de credito invalido";
                        lblErro.Visible = true;
                        return;
                    }
                    if (valor <= 0)
                    {
                        lblErro.Text    = "Um valor invalido foi passado como doacao";
                        lblErro.Visible = true;
                        return;
                    }
                    projeto.arrecadado += valor;
                }
                projeto.Apoios.Add(new Apoios {
                    idDoador = idDoador, idProjeto = projeto.id, valor = valor
                });
                bd.Entry(projeto).State = EntityState.Modified;
                bd.SaveChanges();
                Response.Redirect(Request.RawUrl);
            }
            catch (FormatException)
            {
                lblErro.Text    = "um valor invalido foi passado como doacao";
                lblErro.Visible = true;
                return;
            }
            catch (Exception ex)
            {
                lblErro.Text    = ex.InnerException.ToString();
                lblErro.Visible = true;
                return;
            }
        }
Exemplo n.º 5
0
        public void IsValidTests()
        {
            var attribute = new CreditCardAttribute();

            Assert.IsTrue(attribute.IsValid(null));                              // Don't check for required
            Assert.IsTrue(attribute.IsValid("0000000000000000"));                // Simplest valid value
            Assert.IsTrue(attribute.IsValid("1234567890123452"));                // Good checksum
            Assert.IsTrue(attribute.IsValid("1234-5678-9012-3452"));             // Good checksum, with dashes
            Assert.IsTrue(attribute.IsValid("1234 5678 9012 3452"));             // Good checksum, with spaces
            Assert.IsTrue(attribute.IsValid("541234567890125"));
            Assert.IsTrue(attribute.IsValid("4408041234567893"));
            Assert.IsTrue(attribute.IsValid("4417123456789113"));

            Assert.IsFalse(attribute.IsValid("0000000000000001"));               // Bad checksum
            Assert.IsFalse(attribute.IsValid("0000-0000-0000-0001"));
            Assert.IsFalse(attribute.IsValid("1234567890123456"));
            Assert.IsFalse(attribute.IsValid("---"));
            Assert.IsFalse(attribute.IsValid("4417123456789112"));
            Assert.IsFalse(attribute.IsValid("4408041234567890"));
            Assert.IsFalse(attribute.IsValid("4408041234567890ab"));
            Assert.IsFalse(attribute.IsValid("4408 0412 3456 7890"));
            Assert.IsFalse(attribute.IsValid(0));                                // Non-string
        }
Exemplo n.º 6
0
        /******* HELPER METHODS START ********/

        bool ValidCreditCard(string creditCardNum)
        {
            CreditCardAttribute cardAttribute = new CreditCardAttribute();

            return(cardAttribute.IsValid(creditCardNum));
        }
Exemplo n.º 7
0
        /******* HELPER METHODS START ********/

        /// <summary>
        /// Checks if a string is in a valid credit card format.
        /// </summary>
        /// <param name="creditCardNum">String to validate.</param>
        /// <returns>Returns true if the creditCardNum is in a valid format, otherwise false.</returns>
        bool ValidCreditCard(string creditCardNum)
        {
            CreditCardAttribute cardAttribute = new CreditCardAttribute();

            return(!String.IsNullOrEmpty(creditCardNum) && cardAttribute.IsValid(creditCardNum));
        }
Exemplo n.º 8
0
        public void IsCreditCard_ShouldSuccessfullyValidateACreditCard()
        {
            const string validCardNumber = "1111111111111117";

            creditCardAttribute.IsValid(validCardNumber).ShouldBeTrue();
        }