public AuthorizationResponse ProcessRequest(AuthorizationRequest request) { //Long 3rd party Api call Thread.Sleep(request.Amount > 1000 ? 30000 : 2000); var clearingStatus = request.AccountNumber % 2 == 0 ? ClearingStatus.Authorized : ClearingStatus.Rejected; return new AuthorizationResponse() { TransactionId = request.TransactionId, ClearingStatus = clearingStatus, ProviderTransactionId = $"c#{request.TransactionId}#{Interlocked.Increment(ref _transactionIdSeed)}", ResponseCode = 100, ErrorCode = clearingStatus == ClearingStatus.Authorized ? 0 : 2345 }; }
public async Task Rejects_payment_If_clearingApi_responds_with_Reject() { var sagaId = Guid.NewGuid(); _clearingApi.ProcessRequest(Arg.Any<AuthorizationRequest>()) .Returns(new AuthorizationResponse {ClearingStatus = ClearingStatus.Rejected}); var authorizationRequest = new AuthorizationRequest {TransactionId = sagaId}; Task<AuthorizationResponse> response = null; var req = await Bus.Request(InputQueueAddress, authorizationRequest, x => { response = x.Handle<AuthorizationResponse>(); x.Timeout = TestTimeout; }, TestCancellationToken); await req.Task; Assert.That((await response).ClearingStatus, Is.EqualTo(ClearingStatus.Rejected)); }
public async Task Moves_to_Authorizing_state() { var sagaId = Guid.NewGuid(); _clearingApi.ProcessRequest(Arg.Any<AuthorizationRequest>()).Returns(new AuthorizationResponse()); var authorizationRequest = new AuthorizationRequest {TransactionId = sagaId}; var req = await Bus.Request(InputQueueAddress, authorizationRequest, x => { x.Handle<AuthorizationResponse>(); x.Timeout = TestTimeout; }, TestCancellationToken); await req.Task; var saga = await _repository.ShouldContainSaga(x => x.CorrelationId == sagaId && Equals(x.CurrentState, _machine.Authorizing), TestTimeout); Assert.IsTrue(saga.HasValue); }