public async Task Should_Create_Payment_With_Valid_Card()
        {
            const string BankIdentifier = "1";
            //Arrange
            var payment = TestHelper.Payment;
            var paymentRepositoryMock = new Mock <IPaymentRepository>();

            paymentRepositoryMock.Setup(x => x.Add(It.IsAny <Payment>())).Returns(Task.FromResult(TestHelper.Payment));

            var bankResposne = new BankGatewayResponse {
                Identifier = BankIdentifier, Status = BankGatewayPaymentStatus.Failed
            };
            var bankGatewayMock = new Mock <IBankGateway>();

            bankGatewayMock.Setup(x => x.SubmitPayment(It.IsAny <BankGatewayRequest>())).Returns(Task.FromResult(bankResposne));

            var logger             = Mock.Of <ILogger <PaymentService> >();
            var encryptionProvider = Mock.Of <IEncryptionProvider>();


            var paymentService = new PaymentService(logger, paymentRepositoryMock.Object, bankGatewayMock.Object, encryptionProvider);
            var paymentRequest = Mock.Of <CreatePaymentRequest>();
            var merchant       = Mock.Of <Merchant>();

            //Act
            var expected = await paymentService.CreatePayment(paymentRequest, merchant);

            //Assert
            bankGatewayMock.Verify(x => x.SubmitPayment(It.IsAny <BankGatewayRequest>()), Times.Once());
            paymentRepositoryMock.Verify(x => x.Add(It.IsAny <Payment>()), Times.Once());

            Assert.False(expected.IsSuccessfull);
            Assert.Null(expected.PaymentId);
        }
示例#2
0
 internal static Payment MapPayment(BankGatewayResponse response, Merchant merchant, IEncryptionProvider encryptionProvider)
 {
     return(new Payment
     {
         CardNumber = encryptionProvider.Encrypt(response.CardNumber),
         NameOnCard = encryptionProvider.Encrypt(response.NameOnCard),
         ExpiryDate = encryptionProvider.Encrypt(response.ExpiryDate),
         Amount = response.Amount,
         CreatedOn = DateTime.UtcNow,
         MerchantId = merchant.Id,
         BankGatewayIdentifier = response.Identifier
     });
 }
        public Task <BankGatewayResponse> SubmitPayment(BankGatewayRequest request)
        {
            var result = new BankGatewayResponse
            {
                CardNumber   = request.CardNumber,
                NameOnCard   = request.NameOnCard,
                ExpiryDate   = request.ExpiryDate,
                SecurityCode = request.SecurityCode,
                Amount       = request.Amount,
                Identifier   = Guid.NewGuid().ToString(),
                Status       = BankGatewayPaymentStatus.Failed
            };

            if (request.CardNumber == TestCardNumber)
            {
                result.Status = BankGatewayPaymentStatus.Successfull;
            }

            return(Task.FromResult(result));
        }