Exemplo n.º 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 Can_store_a_payment_for_a_merchant_id()
        {
            var sut = new InMemoryPaymentRepository(NullLogger <InMemoryPaymentRepository> .Instance);

            await sut.Create(
                payment : GeneratePayment(),
                merchantId : Guid.NewGuid());
        }
        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 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);
        }