public void Should_raise_a_PaymentApproved_event_when_Approve_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); // Act aggregate.Approve(BankTransactionId.Create()); // Assert aggregate.Should().HaveRaisedEventOfType <PaymentApproved>(); }
public void Should_set_the_status_to_rejected_when_Reject_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); // Act aggregate.Reject(BankTransactionId.Create()); // Assert aggregate.Status.Should().Be(PaymentStatus.Rejected); }
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_return_true_when_payment_has_been_rejected() { // Arrange var service = new DomainServices.PaymentService(); _payment.Reject(BankTransactionId.Create()); // Act var result = service.HasAlreadyBeenProcessed(_payment); // Assert result.Should().BeTrue(); }
public void Should_raise_a_PaymentRejected_event_when_Reject_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); var transactionId = BankTransactionId.Create(); // Act aggregate.Reject(transactionId); // Assert aggregate.Should().HaveRaisedEventOfType <PaymentRejected>(); aggregate.TransactionId.Should().Be(transactionId); }
public void Should_set_the_status_to_approved_when_Approve_command_is_executed() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); var transactionId = BankTransactionId.Create(); // Act aggregate.Approve(transactionId); // Assert aggregate.Status.Should().Be(PaymentStatus.Approved); aggregate.TransactionId.Should().Be(transactionId); }
public void Should_throw_when_Reject_is_called_and_status_is_not_pending() { // Arrange var aggregate = PaymentFactory.Create(_dateProvider); aggregate.Reject(BankTransactionId.Create()); // Act Action action = () => aggregate.Reject(BankTransactionId.Create()); // Assert action.Should().Throw <PaymentAlreadyProcessedException>(); }
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>(); }
public void Reject(BankTransactionId transactionId) { if (Status != PaymentStatus.Pending) { throw new PaymentAlreadyProcessedException(Id); } if (transactionId == null) { throw new TransactionIdCannotBeNullException(Id); } RaiseEvent(new PaymentRejected(Id, transactionId)); }
internal void Apply(PaymentRejected @event) { Status = PaymentStatus.Rejected; TransactionId = @event.TransactionId; }
public UnknownBankStatusException(string status, BankTransactionId transactionId, PaymentId paymentId) : base($"The transaction {transactionId} for the payment {paymentId} returned an unknown status: {status}") { }
internal void Apply(PaymentApproved @event) { Status = PaymentStatus.Approved; TransactionId = @event.TransactionId; }
public PaymentApproved(PaymentId aggregateId, BankTransactionId transactionId) : base(aggregateId) { TransactionId = transactionId; }
public BankTransactionTests() { _paymentId = PaymentId.Create(); _transactionId = new BankTransactionId(Guid.NewGuid()); }