コード例 #1
0
        public async Task <CreditCardValidityDTO> IsCreditCardValid(string creditCardNumber)
        {
            var encryptedCreditNumber = Cipher.Encrypt(creditCardNumber, CipherConstans.CreditCardKey);
            var isValid = new CreditCardValidityDTO();

            try
            {
                isValid = await _creditCardRepository.GetCreditCardValidity(encryptedCreditNumber);
            }
            catch (Exception ex)
            {
                throw new Exception("Credit card number wasn't found");
            }

            return(isValid);
        }
コード例 #2
0
        public void PostIndex()
        {
            // Arrange
            var model = new CreditCardModel {
                CreditCardNumber = "1111222233334444"
            };
            var creditCardValidityDto = new CreditCardValidityDTO {
                CreditCardId = 1, isValid = true
            };
            var mockRepo = new Mock <ICreditCardService>();

            mockRepo.Setup(x => x.IsCreditCardValid(model.CreditCardNumber))
            .Returns(Task.FromResult(creditCardValidityDto));
            HomeController controller = new HomeController(mockRepo.Object);

            // Act
            var result = controller.Index(model).Result as RedirectToRouteResult;

            // Assert
            Assert.AreEqual("Pin", result.RouteValues["Action"]);
        }