Exemplo n.º 1
0
        public async Task Unit_ProcessClosedPayment_ExpectBadRequest()
        {
            Account newAccount = new Account {
                Name = "Test Account"
            };

            _context.Accounts.Add(newAccount);
            _context.SaveChanges();

            Transaction deposit = new Transaction {
                AccountId = newAccount.Id, Amount = 1000000, Date = new DateTime(2020, 1, 1), TransactionStatus = TransactionStatusEnum.Processed, TransactionType = TransactionTypeEnum.Deposit, CreationDate = new DateTime(2020, 1, 1), LastUpdateDate = new DateTime(2020, 1, 1)
            };

            _context.Transactions.Add(deposit);
            _context.SaveChanges();

            Transaction payment = new Transaction {
                AccountId = newAccount.Id, Amount = 1000, Date = new DateTime(2020, 1, 1), TransactionStatus = TransactionStatusEnum.Closed, TransactionType = TransactionTypeEnum.Withdrawal, CreationDate = new DateTime(2020, 1, 1), LastUpdateDate = new DateTime(2020, 1, 1)
            };

            _context.Transactions.Add(payment);
            _context.SaveChanges();

            TransactionUpdaterService updater = new TransactionUpdaterService(_mockPaymentLogger.Object, _mapper, newAccount.Id, payment.Id, _accountRepo, _transRepo, TransactionStatusEnum.Processed, Messages.Payment_FailedToProcess);
            ServiceResult             result  = await updater.UpdateTransaction();

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
            result.ContentResult.Should().Contain(Messages.Payment_StatusIsClosed);
        }
Exemplo n.º 2
0
        public async Task Unit_ProcessPendingPayment_AccountDoesNotExist_ExpectNotFound()
        {
            TransactionUpdaterService updater = new TransactionUpdaterService(_mockPaymentLogger.Object, _mapper, 1000, 10000, _accountRepo, _transRepo, TransactionStatusEnum.Processed, Messages.Payment_FailedToProcess);
            ServiceResult             result  = await updater.UpdateTransaction();

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status404NotFound);
            result.ContentResult.Should().Contain(Messages.Account_AccountNotFound);
        }
Exemplo n.º 3
0
        public async Task Unit_ProcessPendingPayment_ExpectPaymentProcessedInResult()
        {
            Account newAccount = new Account {
                Name = "Test Account"
            };

            _context.Accounts.Add(newAccount);
            _context.SaveChanges();

            Transaction deposit = new Transaction {
                AccountId = newAccount.Id, Amount = 1000000, Date = new DateTime(2020, 1, 1), TransactionStatus = TransactionStatusEnum.Processed, TransactionType = TransactionTypeEnum.Deposit, CreationDate = new DateTime(2020, 1, 1), LastUpdateDate = new DateTime(2020, 1, 1)
            };

            _context.Transactions.Add(deposit);
            _context.SaveChanges();

            Transaction payment = new Transaction {
                AccountId = newAccount.Id, Amount = 1000, Date = new DateTime(2020, 1, 1), TransactionStatus = TransactionStatusEnum.Pending, TransactionType = TransactionTypeEnum.Withdrawal, CreationDate = new DateTime(2020, 1, 1), LastUpdateDate = new DateTime(2020, 1, 1)
            };

            _context.Transactions.Add(payment);
            _context.SaveChanges();

            TransactionUpdaterService updater = new TransactionUpdaterService(_mockPaymentLogger.Object, _mapper, newAccount.Id, payment.Id, _accountRepo, _transRepo, TransactionStatusEnum.Processed, Messages.Payment_FailedToProcess);
            ServiceResult             result  = await updater.UpdateTransaction();

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(StatusCodes.Status200OK);
            TransactionResultDto transaction = JsonConvert.DeserializeObject <TransactionResultDto>(result.ContentResult);

            transaction.Should().NotBeNull();
            transaction.AccountId.Should().Be(newAccount.Id);
            transaction.Amount.Should().Be(1000);
            transaction.Date.Should().Be(new DateTime(2020, 1, 1));
            transaction.TransactionStatus.Should().Be(TransactionStatusEnum.Processed.ToString());
        }
        public async Task <IActionResult> CancelPayment([FromBody] TransactionCancelDto objDto)
        {
            TransactionUpdaterService updater = new TransactionUpdaterService(_logger, _mapper, (int)objDto.AccountId, (int)objDto.TransactionId, _accountRepo, _transRepo, TransactionStatusEnum.Closed, Messages.Payment_FailedToCancel, objDto.Reason);

            return(this.GetActionResultFromServiceResult(await updater.UpdateTransaction()));
        }