コード例 #1
0
        /// <summary>
        /// Creates a pending transaction and returns the id
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="amount"></param>
        /// <param name="finalizeIn"></param>
        /// <returns></returns>
        public int CreateTransaction(int accountId, decimal amount, TimeSpan? finalizeIn = null)
        {
            // create fund reservation
            var transaction = new CashAccountTransaction
                {
                    AccountId = accountId,
                    StatusId = (int)TransactionStatusType.Pending,
                    Amount = amount,
                    FinalizationDateTime = DateTime.Now + (finalizeIn ?? TimeSpan.Zero),
                    Created = DateTime.Now,
                    Modified = DateTime.Now
                };

            // add to db set
            CashAccountTransactions.Add(transaction);

            // save changes in repository
            SaveChanges();

            // return the id
            return transaction.Id;
        }
コード例 #2
0
        /// <summary>
        /// Creates a pending transaction and returns the id
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="amount"></param>
        /// <param name="finalizeIn"></param>
        /// <returns></returns>
        public int CreateTransaction(int accountId, decimal amount, TimeSpan?finalizeIn = null)
        {
            // create fund reservation
            var transaction = new CashAccountTransaction
            {
                AccountId            = accountId,
                StatusId             = (int)TransactionStatusType.Pending,
                Amount               = amount,
                FinalizationDateTime = DateTime.Now + (finalizeIn ?? TimeSpan.Zero),
                Created              = DateTime.Now,
                Modified             = DateTime.Now
            };

            // add to db set
            CashAccountTransactions.Add(transaction);

            // save changes in repository
            SaveChanges();

            // return the id
            return(transaction.Id);
        }
コード例 #3
0
ファイル: AccountManager.cs プロジェクト: CarlosVV/mediavf
        /// <summary>
        /// Updates the balance for the account from pending transactions
        /// </summary>
        /// <param name="transaction"></param>
        private decimal UpdateBalanceFromPendingTransaction(CashAccountTransaction transaction)
        {
            try
            {
                // process the transaction
                _transactionProcessor.ProcessTransaction(transaction);

                // set the status on the transaction to completed
                transaction.StatusId = (int)TransactionStatusType.Completed;

                // return the amount for the transaction
                return transaction.Amount;
            }
            catch
            {
                // mark as failed
                transaction.StatusId = (int) TransactionStatusType.Failed;

                return 0;
            }
        }
コード例 #4
0
        public void ProcessTransactions_ShouldNotProcessInProgressTransaction()
        {
            // create new cancelled transaction
            var inProgressTransaction = new CashAccountTransaction
            {
                Amount = 500,
                FinalizationDateTime = DateTime.Now.AddDays(-1),
                StatusId = (int)TransactionStatusType.InProgress
            };

            // create account with old transaction
            var account = new CashAccount { Balance = 500, Transactions = new Collection<CashAccountTransaction> { inProgressTransaction } };

            // return account when retrieving from the repository
            A.CallTo(() => _repository.GetAccountWithTransactions(A<int>.Ignored)).Returns(account);

            // process transactions for the account
            _accountManager.ProcessTransactions();

            // transactions should be retrieved from the repository
            A.CallTo(() => _repository.GetAccountWithTransactions(A<int>.Ignored)).MustHaveHappened();

            // account should have been updated
            var newAccount = _accountManager.GetFieldValue<CashAccount>("_account");
            newAccount.Should().Be(account);

            // ensure the transaction was processed
            A.CallTo(() => _transactionProcessor.ProcessTransaction(inProgressTransaction)).MustNotHaveHappened();

            // check that transactions are as expected
            newAccount.Transactions.Should().Contain(t => t == inProgressTransaction);

            // check that balance was updated correctly
            newAccount.Balance.Should().Be(500);
        }
コード例 #5
0
        public void ProcessTransactions_ShouldNotRemoveNewCompletedTransaction()
        {
            // create new cancelled transaction
            var newCompletedTransaction = new CashAccountTransaction
            {
                FinalizationDateTime = DateTime.Now.AddDays(-1),
                StatusId = (int)TransactionStatusType.Completed
            };

            // create account with old transaction
            var account = new CashAccount { Transactions = new Collection<CashAccountTransaction> { newCompletedTransaction } };

            // return account when retrieving from the repository
            A.CallTo(() => _repository.GetAccountWithTransactions(A<int>.Ignored)).Returns(account);

            // process transactions for the account
            _accountManager.ProcessTransactions();

            // transactions should be retrieved from the repository
            A.CallTo(() => _repository.GetAccountWithTransactions(A<int>.Ignored)).MustHaveHappened();

            // account should have been updated
            var newAccount = _accountManager.GetFieldValue<CashAccount>("_account");
            newAccount.Should().Be(account);

            // check that transactions are as expected
            newAccount.Transactions.Should().Contain(t => t == newCompletedTransaction);
        }