Пример #1
0
        public async Task Given_payment_exists_when_get_payment_called_with_payment_id_then_returns_payment()
        {
            var paymentsRepo    = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);
            var existingPayment = new Payment(
                Id: Guid.NewGuid(),
                Amount: new(1.23m, "GBP"),
                Description: "Test Payment",
                Card: new(
                    MaskedPan: "1234",
                    ExpiryMonth: new(2021, 01)
                    ),
                Result: PaymentResult.Succeeded,
                Timestamp: SystemClock.Instance.GetCurrentInstant(),
                CreatedAt: SystemClock.Instance.GetCurrentInstant());
            await paymentsRepo.Create(existingPayment, PaymentController.DefaultMerchant.Id);

            var sut = new PaymentController(paymentsRepo, new AlwaysThrowsPaymentAuthoriser(), SystemClock.Instance, NullLogger <PaymentController> .Instance);

            var result = await sut.Get(existingPayment.Id);

            var actionResult    = Assert.IsType <ActionResult <PaymentResponse> >(result);
            var okResult        = Assert.IsType <OkObjectResult>(actionResult.Result);
            var returnedPayment = Assert.IsType <PaymentResponse>(okResult.Value);

            Assert.Equal(existingPayment.Amount, returnedPayment.Amount);
            Assert.Equal(existingPayment.Description, returnedPayment.Description);
            Assert.Equal(existingPayment.Result, returnedPayment.Result);
        }
        public async Task Returns_null_if_no_payment_with_that_id_exists()
        {
            var sut = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);

            var retrievedPayment = await sut.Get(Guid.NewGuid(), Guid.NewGuid());

            Assert.Null(retrievedPayment);
        }
        public async Task Can_store_a_payment_for_a_merchant_id()
        {
            var sut = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);

            await sut.Create(
                payment : GeneratePayment(),
                merchantId : Guid.NewGuid());
        }
        public void CardPayment_InValidPayments(Card card, BankAccount bankAccount, TransactionStatus resulTransactionStatus)
        {
            var fakeCardRepository        = new FakeCardRepository();
            var fakeBankAccountRepository = new FakeBankAccountRepository();
            var inMemPaymentRepository    = new InMemoryPaymentRepository();
            var service = new CardPaymentService(fakeCardRepository, fakeBankAccountRepository, inMemPaymentRepository);
            CardPaymentResponse response = service.DoPayment(new CardPaymentRequest(requestId1, card, bankAccount));

            Assert.Equal(resulTransactionStatus, response.TransactionStatus);
        }
        public async Task Storing_a_payment_twice_with_the_same_id_throws()
        {
            var sut     = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);
            var payment = GeneratePayment();
            async Task CreatePayment() => await sut.Create(payment : payment, merchantId : Guid.NewGuid());

            await CreatePayment();

            await Assert.ThrowsAsync <PaymentAlreadyExistsException>(CreatePayment);
        }
        public async Task Returns_null_if_no_payment_with_that_id_exists_for_the_provided_merchant_id()
        {
            var sut = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);

            var(payment, merchantId) = (GeneratePayment(), Guid.NewGuid());
            await sut.Create(payment : payment, merchantId : merchantId);

            var retrievedPayment = await sut.Get(payment.Id, Guid.NewGuid());

            Assert.Null(retrievedPayment);
        }
        public void CardPayment_DoublePayment()
        {
            // arrange
            var fakeCardRepository        = new FakeCardRepository();
            var fakeBankAccountRepository = new FakeBankAccountRepository();
            var inMemPaymentRepository    = new InMemoryPaymentRepository();
            // act
            var service = new CardPaymentService(fakeCardRepository, fakeBankAccountRepository, inMemPaymentRepository);
            CardPaymentResponse response = service.DoPayment(new CardPaymentRequest(requestId1, FakeCardRepository.GenerateCard_JohnDoe(), FakeBankAccountRepository.GenerateBankAccount_Amazon()));

            service = new CardPaymentService(new FakeCardRepository(), new FakeBankAccountRepository(), inMemPaymentRepository);
            // act-assert
            Assert.Throws <RequestAlreadyProcessedException>(() => service.DoPayment(new CardPaymentRequest(requestId1, FakeCardRepository.GenerateCard_JohnDoe(), FakeBankAccountRepository.GenerateBankAccount_Amazon())));
        }
Пример #8
0
        public async Task When_authorise_payment_called_with_valid_request_then_payment_is_stored_with_creation_time()
        {
            var paymentsRepo          = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);
            var expectedCreatedAtTime = SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromDays(5));
            var clockStub             = new ConstantTimeClockStub(expectedCreatedAtTime);
            var sut            = new PaymentController(paymentsRepo, new AlwaysApprovesPaymentAuthoriser(), clockStub, NullLogger <PaymentController> .Instance);
            var paymentRequest = _generatePaymentRequest();

            var result = await sut.Authorise(paymentRequest);

            var createdPayment = ExpectSuccessResponseWithCreatedPayment(result);
            var storedPayment  = await paymentsRepo.Get(createdPayment.Id, PaymentController.DefaultMerchant.Id);

            Assert.Equal(expectedCreatedAtTime, storedPayment.CreatedAt);
        }
        public async Task Can_retrieve_a_stored_payment_for_a_merchant_id()
        {
            var sut = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);

            var(payment, merchantId) = (GeneratePayment(), Guid.NewGuid());
            await sut.Create(payment : payment, merchantId : merchantId);

            var retrievedPayment = await sut.Get(payment.Id, merchantId);

            Assert.Equal(payment.Amount, retrievedPayment.Amount);
            Assert.Equal(payment.Card, retrievedPayment.Card);
            Assert.Equal(payment.Id, retrievedPayment.Id);
            Assert.Equal(payment.Description, retrievedPayment.Description);
            Assert.Equal(payment.Result, retrievedPayment.Result);
            Assert.Equal(payment.Timestamp, retrievedPayment.Timestamp);
        }
Пример #10
0
 public InMemoryPaymentRepositoryTests()
 {
     _dbContextCreator = new DbContextCreator();
     _repo             = new InMemoryPaymentRepository(_dbContextCreator.CreateDbContext());
 }