Пример #1
0
        public async Task CreatePaymentRequestShouldReturn201Response()
        {
            MockPaymentsRepository.Setup(x => x.AddPayment(It.IsAny <PaymentEntry>())).ReturnsAsync(new BaseResult()
            {
                Success = true, Message = "example message"
            });

            MockBankRepository.Setup(x => x.RequestPayment(It.IsAny <MockBankPaymentRequest>())).Returns(new MockBankResponse()
            {
                Identifier = Guid.NewGuid().ToString(), Status = CheckOut.PaymentGateway.Core.Enum.PaymentStatus.Authorized
            });

            var response = await this.Controller.CreatePayment(FakeCreatePaymentData.FakeCreatePaymentRequest()) as CreatedAtActionResult;


            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Value);
            Assert.AreEqual(201, response.StatusCode);
        }
Пример #2
0
        public async void CreatePaymentTestShouldReturnNullWhenBankFailsToProcessPayment()
        {
            //update mockBankRepository to return failed payments
            MockBankRepository mockBankRepositoryFailProcess = new MockBankRepository(processPaymentSuccess: false);

            paymentsService = new PaymentsService(mockBankRepositoryFailProcess, paymentRepository);
            Payment paymentResult = await paymentsService.CreatePayment(new Payment
            {
                Amount         = 449.99F,
                CustomerEmail  = "*****@*****.**",
                CustomerName   = "John Doe",
                CardExpiryDate = new DateTime(2019, 12, 1),
                CardNumber     = "123456789101112",
                Currency       = "GBP",
                CVV            = "333"
            });

            Assert.Null(paymentResult);
        }
Пример #3
0
        public void ProcessPaymentShouldBeAFailWhenDAtaAccessCallFails()
        {
            MockBankRepository.Setup(x => x.RequestPayment(It.IsAny <MockBankPaymentRequest>()))
            .Returns(new MockBankResponse()
            {
                HttpStatus = System.Net.HttpStatusCode.OK,
                Identifier = "Dummy",
                Status     = COPaymentGateWay.Core.Enum.PaymentStatus.Authorized
            });

            MockPaymentsDataAccess.Setup(x => x.AddPayment(It.IsAny <PaymentEntry>()))
            .ReturnsAsync(new BaseResult()
            {
                Success = false
            });

            var res = this.PaymentsRepository.ProcessPayment(Fakes.FakePaymentData.FakePaymentEntryData());

            Assert.IsTrue(res.IsCompletedSuccessfully);
            Assert.IsFalse(res.Result.Success);

            MockBankRepository.Verify(x => x.RequestPayment(It.IsAny <MockBankPaymentRequest>()), Times.Once);
            MockPaymentsDataAccess.Verify(x => x.AddPayment(It.IsAny <PaymentEntry>()), Times.Exactly(2));
        }