Ejemplo n.º 1
0
        public async Task <BankTransaction> ProcessPayment(Payment payment)
        {
            var status        = _random.Next(100) <= 50 ? BankTransactionStatus.Success : BankTransactionStatus.Failed;
            var transactionId = new BankTransactionId(Guid.NewGuid());
            var result        = BankTransaction.Create(transactionId, status, payment.Id);

            // Simulate http latency
            await Task.Delay(TimeSpan.FromSeconds(_random.Next(3)));

            return(result);
        }
        public void Should_throw_when_payment_is_null()
        {
            // Arrange
            var transactionId = new BankTransactionId(Guid.NewGuid());
            var transaction   = BankTransaction.Create(transactionId, BankTransactionStatus.Failed, _payment.Id);

            // Act
            Action action = () => _service.UpdatePayment(null, transaction);

            // Assert
            action.Should().Throw<ArgumentNullException>();
        }
        public void Should_reject_payment_when_transaction_status_is_failed()
        {
            // Arrange
            var transactionId = new BankTransactionId(Guid.NewGuid());
            var transaction   = BankTransaction.Create(transactionId, BankTransactionStatus.Failed, _payment.Id);

            // Act
            _service.UpdatePayment(_payment, transaction);

            // Assert
            _payment.Status.Should().Be(PaymentStatus.Rejected);
        }
        public void Should_approve_payment_when_transaction_status_is_success()
        {
            // Arrange
            var transactionId = new BankTransactionId(Guid.NewGuid());
            var transaction   = BankTransaction.Create(transactionId, BankTransactionStatus.Success, _payment.Id);

            // Act
            _service.UpdatePayment(_payment, transaction);

            // Assert
            _payment.Status.Should().Be(PaymentStatus.Approved);
        }
        public void Should_throw_when_bank_transaction_status_is_unknown()
        {
            // Arrange
            var transactionId = new BankTransactionId(Guid.NewGuid());
            var transaction   = BankTransaction.Create(transactionId, BankTransactionStatus.Failed, _payment.Id);
            ReflectionHelper.UpdatePrivateProperty(transaction, nameof(transaction.Status), 1337);

            // Act
            Action action = () => _service.UpdatePayment(_payment, transaction);

            // Assert
            action.Should().Throw<UnknownBankStatusException>();
        }
Ejemplo n.º 6
0
        public void Should_raise_an_error_when_payment_id_is_null()
        {
            Action action = () => BankTransaction.Create(_transactionId, BankTransactionStatus.Success, null);

            action.Should().Throw <ValidationException>();
        }
Ejemplo n.º 7
0
        public void Should_raise_an_error_when_status_has_incorrect_value()
        {
            Action action = () => BankTransaction.Create(_transactionId, (BankTransactionStatus)1337, _paymentId);

            action.Should().Throw <ValidationException>();
        }