Esempio n. 1
0
        public void EmptyModelShouldThrowValidationErrors()
        {
            var model = new PaymentRequestSource();

            var results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count > 0);
        }
Esempio n. 2
0
        public void NumberShouldBeRequired()
        {
            var model = new PaymentRequestSource()
            {
                Cvv         = "333",
                ExpiryMonth = 12,
                ExpiryYear  = DateTime.Now.Year,
                Name        = "Kamal",
                Type        = "card"
            };

            var results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("Number"));
        }
Esempio n. 3
0
        public void FullModelShouldNotThrowValidationErrors()
        {
            var model = new PaymentRequestSource()
            {
                Cvv         = "333",
                ExpiryMonth = 12,
                ExpiryYear  = DateTime.Now.Year,
                Name        = "Kamal",
                Number      = "4111111111111111",
                Type        = "card"
            };

            var results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 0);
        }
Esempio n. 4
0
        public void ExpiryMonthBetweenOneAndTwelve()
        {
            var model = new PaymentRequestSource()
            {
                Cvv         = "333",
                ExpiryMonth = 1,
                ExpiryYear  = DateTime.Now.Year,
                Name        = "Kamal",
                Number      = "4111111111111111",
                Type        = "card"
            };

            for (int i = 0; i < 14; i++)
            {
                model.ExpiryMonth = i;

                var results = TestModelHelper.Validate(model);
                Assert.IsTrue(results.Count == (i > 0 && i <= 12 ? 0 : 1));
            }
        }
Esempio n. 5
0
        public void ExpiryDateBetweenNowAndTenYears()
        {
            var model = new PaymentRequestSource()
            {
                Cvv         = "333",
                ExpiryMonth = 12,
                ExpiryYear  = DateTime.Now.Year,
                Name        = "Kamal",
                Number      = "4111111111111111",
                Type        = "card"
            };

            var results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 0);

            model.ExpiryYear = DateTime.Now.Year - 1;
            results          = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("ExpiryYear"));

            model.ExpiryYear = DateTime.Now.Year + 5;
            results          = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 0);

            model.ExpiryYear = DateTime.Now.Year + 10;
            results          = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 0);

            model.ExpiryYear = DateTime.Now.Year + 11;
            results          = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("ExpiryYear"));
        }
Esempio n. 6
0
        public void CVVLength()
        {
            var model = new PaymentRequestSource()
            {
                Cvv         = "333",
                ExpiryMonth = 12,
                ExpiryYear  = DateTime.Now.Year,
                Name        = "Kamal",
                Number      = "4111111111111111",
                Type        = "card"
            };

            var results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 0);

            model.Cvv = "33";

            results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("Cvv"));

            model.Cvv = "3333";

            results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 0);

            model.Cvv = "33333";

            results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("Cvv"));
        }
Esempio n. 7
0
        public void CardNumberShouldHaveCorrectFormat()
        {
            var model = new PaymentRequestSource()
            {
                Cvv         = "333",
                ExpiryMonth = 12,
                ExpiryYear  = DateTime.Now.Year,
                Name        = "Kamal",
                Number      = "411111111111",
                Type        = "card"
            };

            var results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("Number"));

            model.Number = "A111111111111111";

            results = TestModelHelper.Validate(model);

            Assert.IsTrue(results.Count == 1);
            Assert.IsTrue(results[0].MemberNames.Contains("Number"));
        }