Beispiel #1
0
        public void PaymentCardReqVM_ShouldReturnErrorIfExpiryMonthInvlaid(int month)
        {
            // Arrange

            PaymentCardReqVM paymentCardReqVM = MockPaymentCardReqVM.Get();

            paymentCardReqVM.ExpiryMonth = month;

            List <ValidationResult> validationResults = new List <ValidationResult>();

            // Act

            bool isValid = Validator.TryValidateObject(paymentCardReqVM, new ValidationContext(paymentCardReqVM), validationResults, true);

            ValidationResult expiryMonthErrorMessage = validationResults
                                                       .FirstOrDefault(e => e.MemberNames.FirstOrDefault() == nameof(paymentCardReqVM.ExpiryMonth));

            // Assert

            Assert.IsFalse(isValid);
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual($"The field ExpiryMonth must be between 1 and 12.", expiryMonthErrorMessage.ErrorMessage);
        }
Beispiel #2
0
        public void PaymentCardReqVM_ShouldReturnErrorIfCardnumberInvlaid(string cardnumber)
        {
            // Arrange

            PaymentCardReqVM paymentCardReqVM = MockPaymentCardReqVM.Get();

            paymentCardReqVM.Cardnumber = cardnumber;

            List <ValidationResult> validationResults = new List <ValidationResult>();

            // Act

            bool isValid = Validator.TryValidateObject(paymentCardReqVM, new ValidationContext(paymentCardReqVM), validationResults, true);

            ValidationResult cardnumberErrorMessage = validationResults
                                                      .FirstOrDefault(e => e.MemberNames.FirstOrDefault() == nameof(paymentCardReqVM.Cardnumber));

            // Assert

            Assert.IsFalse(isValid);
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual("The Cardnumber field is not a valid card number.", cardnumberErrorMessage.ErrorMessage);
        }
Beispiel #3
0
        public void PaymentCardReqVM_ShouldReturnErrorIfCvvInvlaid(string cvv, Issuer issuer, string error)
        {
            // Arrange

            PaymentCardReqVM paymentCardReqVM = MockPaymentCardReqVM.Get();

            paymentCardReqVM.Cvv    = cvv;
            paymentCardReqVM.Issuer = issuer;

            List <ValidationResult> validationResults = new List <ValidationResult>();

            // Act

            bool isValid = Validator.TryValidateObject(paymentCardReqVM, new ValidationContext(paymentCardReqVM), validationResults, true);

            ValidationResult cvvErrorMessage = validationResults
                                               .FirstOrDefault(e => e.MemberNames.FirstOrDefault() == nameof(paymentCardReqVM.Cvv));

            // Assert

            Assert.IsFalse(isValid);
            Assert.AreEqual(1, validationResults.Count);
            Assert.AreEqual($"The Cvv field must be {error}", cvvErrorMessage.ErrorMessage);
        }