public void Test_card_types() { // The PassesCardType function tests the first few digits of a credit card to make sure // that the length matches a valid card type. // The following card numbers do not need to be valid "Luhn" card numbers but just have // to be the correct length and start with the correct numbers to pass this test. List <string> validNumbers = new List <string>(); List <string> invalidNumbers = new List <string>(); // CARD TYPE Prefix Length // VISA 4 13 validNumbers.Add("4234567890123"); invalidNumbers.Add("1234567890123"); // Diners Club/Carte Blanche 300-305, 36, 38 14 validNumbers.Add("30045678901234"); validNumbers.Add("36345678901234"); validNumbers.Add("38345678901234"); validNumbers.Add("30045678901234"); invalidNumbers.Add("10545678901234"); // enRoute 2014, 2149 15 validNumbers.Add("201456789012345"); validNumbers.Add("214956789012345"); invalidNumbers.Add("801456789012345"); // AMEX 34, 37 15 validNumbers.Add("341456789012345"); validNumbers.Add("371456789012345"); invalidNumbers.Add("311456789012345"); // JCB 2131, 1800 15 validNumbers.Add("213156789012345"); validNumbers.Add("180056789012345"); // Discover 6011 16 // JCB 3 16 // MASTERCARD 51-55 16 // VISA 4 16 validNumbers.Add("6011567890123456"); validNumbers.Add("3014567890123456"); validNumbers.Add("5114567890123456"); validNumbers.Add("5514567890123456"); validNumbers.Add("4234567890123456"); invalidNumbers.Add("8514567890123456"); invalidNumbers.Add("9514567890123456"); invalidNumbers.Add("1514567890123456"); invalidNumbers.Add("1234567890123456"); // Voyager 8699 validNumbers.Add("869972808239529"); invalidNumbers.Add("869872808239529"); CreditCardDerived cc = new CreditCardDerived(); foreach (string s in validNumbers) { Assert.IsTrue(cc.PassesCardType_ForUnitTest(s), s); } foreach (string s in invalidNumbers) { Assert.IsFalse(cc.PassesCardType_ForUnitTest(s), s); } }
public void Test_with_period_at_end_of_number() { string text = "This is a body of text containing visa cc 4485230168606183 and 4485230168606191. And the start of a new sentance."; CreditCardDerived ccd = new CreditCardDerived(); Assert.AreEqual(2, ccd.CreditCardNumbersInText(text).Count); }
public void Test_credit_card_email_count_with_hex() { string email = "This is a fake Mastercard number: 5300042628491142\n\nand this is the same number 5300042628491142abcd with four hex characters after it,\n\nand again with abcd5300042628491142 four hex characters before it, \n\nand again with ab5300042628491142cd with two hex before and after it."; CreditCardDerived ccd = new CreditCardDerived(); List <Capture> captureList = ccd.CreditCardNumbersInText(email); Assert.AreEqual(1, captureList.Count); }
public void trim_non_digits_zero_length() { CreditCardDerived ccd = new CreditCardDerived(); string text = ""; string expected = ""; string actual = ccd.TrimNotDigits_ForUnitTest(text); Assert.AreEqual(expected, actual); }
public void trim_non_digits() { CreditCardDerived ccd = new CreditCardDerived(); string text = "tga12341234ytm"; string expected = "12341234"; string actual = ccd.TrimNotDigits_ForUnitTest(text); Assert.AreEqual(expected, actual); }
public void Test_consecutive_hex_characters() { CreditCardDerived cc = new CreditCardDerived(); Assert.AreEqual <int>(0, cc.CountConsecutiveHexChar_ForUnitTest("xyz")); Assert.AreEqual <int>(3, cc.CountConsecutiveHexChar_ForUnitTest("abc")); Assert.AreEqual <int>(6, cc.CountConsecutiveHexChar_ForUnitTest("abcdefghi")); Assert.AreEqual <int>(16, cc.CountConsecutiveHexChar_ForUnitTest("1234567890abcdefghi")); Assert.AreEqual <int>(16, cc.CountConsecutiveHexChar_ForUnitTest("1234567890abcdefghi".ToUpper())); Assert.AreEqual <int>(5, cc.CountConsecutiveHexChar_ForUnitTest("12345xyz67890abcdefghi")); }
public void trim_non_digits_big_text() { // This test was written when the function was refactored for performance. This test // should take no more than 1 second to run. Previously it was taking 21 seconds to run. int repeat = 10000; CreditCardDerived ccd = new CreditCardDerived(); string lotsOfCharacters = String.Join("", Enumerable.Repeat("abcdef", repeat).ToArray()); string text = lotsOfCharacters + "1" + lotsOfCharacters; string expected = "1"; string actual = ccd.TrimNotDigits_ForUnitTest(text); Assert.AreEqual(expected, actual); }
public void pass_null_as_string_to_function() { CreditCardDerived ccd = new CreditCardDerived(); string text = null; bool result = ccd.ReplaceAllButLastFourWithStars(ref text); Assert.IsFalse(result); Assert.IsNull(text); text = String.Empty; result = ccd.ReplaceAllButLastFourWithStars(ref text); Assert.IsFalse(result); Assert.AreEqual(String.Empty, text); }
public void Test_credit_card_email_replacement_with_hex() { string email = "This is a fake Mastercard number: 5300042628491142\n\nand this is the same number 5300042628491142abcd with four hex characters after it,\n\nand again with abcd5300042628491142 four hex characters before it, \n\nand again with ab5300042628491142cd with two hex before and after it."; CreditCardDerived ccd = new CreditCardDerived(); bool result = ccd.ReplaceAllWithStars(ref email); Assert.IsTrue(result); Assert.AreEqual(16, email.ToCharArray().Where(a => a == '*').Count()); email = "5300042628491142"; Assert.IsTrue(ccd.ReplaceAllWithStars(ref email)); Assert.AreEqual(16, email.ToCharArray().Where(a => a == '*').Count()); email = "5300042628491142xyz5300042628491134"; Assert.IsTrue(ccd.ReplaceAllWithStars(ref email)); Assert.AreEqual(32, email.ToCharArray().Where(a => a == '*').Count()); }
public void Test_credit_card_sanity_check() { string[] validCreditCards = { "4111-1111-1111-1111", "3782-822463-10005", "5105-1051-0510-5100", "6011-1111-1111-1117" }; CreditCardDerived cc = new CreditCardDerived(); foreach (string s in validCreditCards) { Assert.IsTrue(cc.PassesCreditCardSanityCheck_ForUnitTest(s), String.Format("Should pass sanity check but fails for {0}", s)); } string[] invalidCreditCards = { "4111-0000-0000-0000-1234", "0000-0000-0000-0000", "0000-0000-0000", "4321-4321-43Z1-4321" }; foreach (string s in invalidCreditCards) { Assert.IsFalse(cc.PassesCreditCardSanityCheck_ForUnitTest(s), String.Format("Should fail sanity check but passes for {0}", s)); } }
public void Test_string_reverse_function() { CreditCardDerived cc = new CreditCardDerived(); Assert.AreEqual <string>("fedcba", cc.Reverse_ForUnitTest("abcdef")); }