public void Should_not_process_already_queued_accounts()
        {
            _accountProcessQueue.Enqueue(Arg.Any <string[]>()).Returns(new string[0]);

            var transactions = _transactionService.AddNewTransactionsForAccounts(new string[2]);

            Assert.AreEqual(transactions.Result.Count(), 0);
            _transactionRepository.DidNotReceive().AddRangeAsync(Arg.Any <IEnumerable <Domain.Transaction> >());
            _unitOfWork.DidNotReceive().CommitAsync();
        }
Exemple #2
0
        public async Task <IEnumerable <Transaction> > AddNewTransactionsForAccounts(IEnumerable <string> accountIds)
        {
            var newTransactions = new List <Transaction>();
            var queuedAccounts  = _accountProcessQueue.Enqueue(accountIds).ToList();

            foreach (var accountId in queuedAccounts)
            {
                await _accountRepository.AddIfNotExistsAsync(accountId);

                var transactions = await GetNewTransactions(accountId);

                await _transactionRepository.AddRangeAsync(transactions);

                await _unitOfWork.CommitAsync();

                newTransactions.AddRange(transactions);
            }

            _accountProcessQueue.Dequeue(queuedAccounts);
            return(newTransactions);
        }
 private IAccountProcessQueue MockAccountProcessQueue()
 {
     _accountProcessQueue = Substitute.For <IAccountProcessQueue>();
     _accountProcessQueue.Enqueue(Arg.Any <string[]>()).Returns(new string[2]);
     return(_accountProcessQueue);
 }