Exemple #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);
        }
Exemple #2
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));
        }