public IActionResult MakePayment([FromBody] PaymentDto dto) { var errors = dto.Validate(Context); if (!AuthenticatedUserIsOwnerOfPaymentMethod(dto.PaymentMethodId)) { errors.Add("The logged user is not the same as the owner of the account"); } if (errors.Any()) { return(BadRequest(errors)); } var amount = Context.PaymentButtons.Single(x => x.Id == dto.ButtonId).Amount; var transaction = TransactionBuilder.Build(dto, amount); Context.Transactions.Add(transaction); Context.SaveChangesAsync(); var isSuccessful = Saga.Start(transaction.Movements); if (!isSuccessful) { return(BadRequest()); } return(Ok(transaction.Id)); }
public void test_01_all_movements_succeed_in_first_setp() { var movements = new List <Movement> { GetSuccesfullMovement(), GetSuccesfullMovement() }; Saga.Start(movements).Should().BeTrue(); movements.Select(x => x.InProcess).Should().AllBeEquivalentTo(true); movements.Select(x => x.IsSuccesfull).Should().AllBeEquivalentTo(false); }
public void test_03_last_movement_fails_so_all_rollback() { var movements = new List <Movement> { GetSuccesfullMovement(), GetFailedMovement() }; Saga.Start(movements); movements[0].IsRollback.Should().BeTrue(); movements.Select(x => x.Started).Should().AllBeEquivalentTo(true); movements.Select(x => x.InProcess).Should().AllBeEquivalentTo(false); }
public void test_02_first_movements_fails_so_no_rollbacks() { var movements = new List <Movement> { GetFailedMovement(), GetSuccesfullMovement() }; Saga.Start(movements); movements[0].Started.Should().BeTrue(); movements[0].InProcess.Should().BeFalse(); movements[0].IsSuccesfull.Should().BeFalse(); movements[1].IsRollback.Should().BeFalse(); movements[1].Started.Should().BeFalse(); }