Exemplo n.º 1
0
        public void TestRandomMasterCardNumber()
        {
            var testResult = MasterCardCc.RandomMasterCardNumber();

            Assert.IsNotNull(testResult);
            Assert.IsNotNull(testResult.Value);
            Assert.AreEqual(16, testResult.Value.Length);
            Assert.IsTrue(Regex.IsMatch(testResult.Value, "^5[1-5]"));
            Console.WriteLine(testResult.ToString());
        }
Exemplo n.º 2
0
        public void TestMasterCardCcCtor()
        {
            var ccNum = "54331142445527120";

            try
            {
                var badLength = new MasterCardCc(ccNum, new VocaBase("Bee Cardholder"), null, null);
                Assert.Fail($"The value {ccNum} is too long and should have failed.");
            }
            catch (ArgumentException)
            {
                Assert.Pass();
            }

            ccNum = "5433114244552712";
            var isValid = new MasterCardCc(ccNum, new VocaBase("Bee Cardholder"), null, null);

            Assert.IsNotNull(isValid);

            ccNum = "5433114244552710";
            try
            {
                var badChkDigit = new MasterCardCc(ccNum, new VocaBase("Bee Cardholder"), null, null);
                Assert.Fail($"The value {ccNum} has the wrong check digit.");
            }
            catch (ArgumentException)
            {
                Assert.Pass();
            }

            ccNum = "6011723257285586";
            try
            {
                var badChkDigit = new MasterCardCc(ccNum, new VocaBase("Bee Cardholder"), null, null);
                Assert.Fail($"The value {ccNum} is not MC pattern");
            }
            catch (ArgumentException)
            {
                Assert.Pass();
            }
        }