Exemplo n.º 1
0
        public void Debit_Should_Be_Loaded()
        {
            Debit debit = Debit.Load(Guid.Empty, Guid.Empty, 100, DateTime.Today);

            Assert.Equal(Guid.Empty, debit.Id);
            Assert.Equal(Guid.Empty, debit.AccountId);
            Assert.Equal(100, debit.Amount);
            Assert.Equal(DateTime.Today, debit.TransactionDate);
            Assert.Equal("Debit", debit.Description);
        }
        public async Task <AccountResult> GetAccount(Guid accountId)
        {
            Entities.Account account = await _context
                                       .Accounts
                                       .FindAsync(accountId);

            List <Entities.Credit> credits = await _context
                                             .Credits
                                             .Where(e => e.AccountId == accountId)
                                             .ToListAsync();

            List <Entities.Debit> debits = await _context
                                           .Debits
                                           .Where(e => e.AccountId == accountId)
                                           .ToListAsync();

            List <ITransaction> transactions = new List <ITransaction>();

            foreach (Entities.Credit transactionData in credits)
            {
                Credit transaction = Credit.Load(
                    transactionData.Id,
                    transactionData.AccountId,
                    transactionData.Amount,
                    transactionData.TransactionDate);

                transactions.Add(transaction);
            }

            foreach (Entities.Debit transactionData in debits)
            {
                Debit transaction = Debit.Load(
                    transactionData.Id,
                    transactionData.AccountId,
                    transactionData.Amount,
                    transactionData.TransactionDate);

                transactions.Add(transaction);
            }

            var orderedTransactions = transactions.OrderBy(o => o.TransactionDate).ToList();

            TransactionCollection transactionCollection = new TransactionCollection();

            transactionCollection.Add(orderedTransactions);

            Account result = Account.Load(
                account.Id,
                account.CustomerId,
                transactionCollection);

            AccountResult re = new AccountResult(result);

            return(re);
        }