public void ThenTheBalanceShouldBeDollars(int balance) { accountService.PrintStatement(); A.CallTo(() => printerSystem.PrintLine("DATE | AMOUNT | BALANCE")).MustHaveHappened(); A.CallTo(() => printerSystem.PrintLine("10/04/2014 | 500,00 | 1400,00")).MustHaveHappened(); A.CallTo(() => printerSystem.PrintLine("02/04/2014 | -100,00 | 900,00")).MustHaveHappened(); A.CallTo(() => printerSystem.PrintLine("01/04/2014 | 1000,00 | 1000,00")).MustHaveHappened(); }
public void PrintStatement() { IEnumerable <AccountTransaction> transactions = _storage.GetAllTransactions(); _printerSystem.PrintLine("DATE | AMOUNT | BALANCE"); var transactionsOrdered = transactions.OrderByDescending(t => t.Date).ToList(); decimal balance = 0; foreach (var accountTransaction in transactionsOrdered) { balance += accountTransaction.Amount; _printerSystem.PrintLine(string.Format("{0} | {1} | {2}", accountTransaction.Date.ToString("d"), accountTransaction.Amount.ToString("F2"), balance.ToString("F2"))); } }