public AccountBuilder WithInvestments(params decimal[] values) { var list = new List <Investment>(); foreach (var value in values) { list.Add(Investment.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, value) }), MonthYear.Now)); } Investments = new FinanceStatementCollection(list); return(this); }
public AccountBuilder WithInvestments(int length = 2) { var list = new List <Investment>(); for (int i = 0; i < length; i++) { list.Add(Investment.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, GenerateDecimal()) }), MonthYear.Now)); } Investments = new FinanceStatementCollection(list); return(this); }
public AccountBuilder WithInvestment(Guid investmentId, Guid firstAmountRecordId, params decimal[] amountRecordValues) { Investment investment = Investment.Load(investmentId, GenerateName(5), new AmountRecordCollection(), MonthYear.Now); investment.AmountRecords.Add(AmountRecord.Load(firstAmountRecordId, GenerateName(5), amountRecordValues[0])); for (int i = 1; i < amountRecordValues.Length; i++) { investment.AmountRecords.Add(AmountRecord.Load(Guid.NewGuid(), GenerateName(5), amountRecordValues[i])); } Investments.Add(investment); return(this); }
public void Should_Get_Investment() { Guid investmentId = Guid.NewGuid(); Account account = new Account(); Investment investment = Investment.Load(investmentId, "bonus", null, MonthYear.Now); account.GetCollecion <Investment>().Add(investment); var result = account.Get <Investment>(x => x.Id == investmentId); Assert.Equal(investment, result); Assert.IsType <Investment>(result); }
public AccountBuilder WithInvestments(Guid firstItemId, params decimal[] values) { var list = new List <Investment>(); list.Add(Investment.Load(firstItemId, GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, values[0]) }), MonthYear.Now)); for (int i = 1; i < values.Length; i++) { list.Add(Investment.Load(Guid.NewGuid(), GenerateName(9), new AmountRecordCollection(new[] { AmountRecord.Load(Guid.NewGuid(), null, values[i]) }), MonthYear.Now)); } Investments = new FinanceStatementCollection(list); return(this); }
public async Task <AccountQueryResult> GetAccount(System.Guid accountId) { Entities.Account account = await _context .Accounts .Find(x => x.Id == accountId) .SingleOrDefaultAsync(); if (account == null) { throw new AccountNotFoundException($"The account {accountId} does not exists"); } if (!account.Actived) { throw new AccountDeactivatedException($"The account {accountId} is deactivated!"); } IEnumerable <Entities.FinanceStatement> incomes = await _context .Incomes .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> expenses = await _context .Expenses .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> investments = await _context .Investments .Find(x => x.AccountId == accountId) .ToListAsync(); FinanceStatementCollection incomeCollection = new FinanceStatementCollection(); foreach (var income in incomes) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == income.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); incomeCollection.Add(Income.Load(income.Id, income.Title, amountRecordCollection, income.ReferenceDate)); } FinanceStatementCollection expenseCollection = new FinanceStatementCollection(); foreach (var expense in expenses) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == expense.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); expenseCollection.Add(Expense.Load(expense.Id, expense.Title, amountRecordCollection, expense.ReferenceDate)); } FinanceStatementCollection investmentsCollection = new FinanceStatementCollection(); foreach (var investment in investments) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == investment.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); investmentsCollection.Add(Investment.Load(investment.Id, investment.Title, amountRecordCollection, investment.ReferenceDate)); } AccountQueryResult result = new AccountQueryResult(account.Id, expenseCollection, incomeCollection, investmentsCollection); return(result); }
public async Task <Account> Get(Guid accountId) { Entities.Account account = await _context .Accounts .Find(x => x.Id == accountId) .SingleOrDefaultAsync(); IEnumerable <Entities.FinanceStatement> incomes = await _context .Incomes .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> expenses = await _context .Expenses .Find(x => x.AccountId == accountId) .ToListAsync(); IEnumerable <Entities.FinanceStatement> investments = await _context .Investments .Find(x => x.AccountId == accountId) .ToListAsync(); FinanceStatementCollection incomeCollection = new FinanceStatementCollection(); foreach (var income in incomes) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == income.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); incomeCollection.Add(Income.Load(income.Id, income.Title, amountRecordCollection, income.ReferenceDate)); } FinanceStatementCollection expenseCollection = new FinanceStatementCollection(); foreach (var expense in expenses) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == expense.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); expenseCollection.Add(Expense.Load(expense.Id, expense.Title, amountRecordCollection, expense.ReferenceDate)); } FinanceStatementCollection investmentsCollection = new FinanceStatementCollection(); foreach (var investment in investments) { IEnumerable <Entities.AmountRecord> amountRecords = await _context .AmountRecords .Find(x => x.FinanceStatementId == investment.Id) .ToListAsync(); AmountRecordCollection amountRecordCollection = new AmountRecordCollection(amountRecords.Select(x => AmountRecord.Load(x.Id, x.Description, x.Amount))); investmentsCollection.Add(Investment.Load(investment.Id, investment.Title, amountRecordCollection, investment.ReferenceDate)); } Account result = Account.Load( account.Id, account.Actived, incomeCollection, expenseCollection, investmentsCollection ); return(result); }