public void ValidateCreditCardWithWrongLengthReturnsFalse()
        {
            string cardNumber = "7348734";

            Assert.False(
                CardNumberValidator.Validate(cardNumber));
        }
        public void ValidateCreditCardWithValidNumberReturnsTrue()
        {
            string cardNumber = "4234567191015555";

            Assert.True(
                CardNumberValidator.Validate(cardNumber));
        }
        public void ValidateCreditCardWithInvalidNumberReturnsFalse()
        {
            string cardNumber = "4234567x91015555";

            Assert.False(
                CardNumberValidator.Validate(cardNumber));
        }
Пример #4
0
        /// <summary>
        /// Simulates a payment authorization, invalid expiry or card number or a payment does not match the payment policy returns false as status
        /// </summary>
        /// <param name="paymentAuthorizationRequest"></param>
        /// <returns>Indicating the current payment authorization response in <see cref="PaymentAuthorizationResponse"/>.</returns>
        public PaymentAuthorizationResponse AuthorizePayment(
            PaymentAuthorizationRequest paymentAuthorizationRequest)
        {
            // Check payment based on the payment policy
            if (_paymentPolicy.MaxAllowedAmount < paymentAuthorizationRequest.Amount ||
                _paymentPolicy.MinAllowedAmount > paymentAuthorizationRequest.Amount ||
                _paymentPolicy.AllowedCurrencies.Count(c => c.Code == paymentAuthorizationRequest.Currency) == 0 ||
                !ExpiryValidator.Validate(paymentAuthorizationRequest.Expiry) ||
                !CardNumberValidator.Validate(paymentAuthorizationRequest.CardNumber))
            {
                return(new PaymentAuthorizationResponse(Guid.NewGuid(), false));
            }

            return(new PaymentAuthorizationResponse(Guid.NewGuid(), true));
        }
 public void SetUp()
 {
     // Sut instantiation
     _cardNumberValidator = new CardNumberValidator();
 }