public void ShouldReturnStatementsInDescendingDateOrderWhenPrintingBalance()
        {
            DateTime                today        = DateTime.Now;
            ITransactions           transactions = Substitute.For <ITransactions>();
            List <AccountStatement> statements   = new List <AccountStatement>
            {
                new AccountStatement(today.AddDays(2), 100, 200),
                new AccountStatement(today.AddDays(1), -100, 100),
                new AccountStatement(today, 200, 200)
            };
            IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>();

            balanceRetriever.GetStatements().Returns(statements);
            var bankingService = new BankingService(transactions, balanceRetriever);

            var balance = bankingService.PrintBalance();

            var expectedStatements = new List <AccountStatement>
            {
                new AccountStatement(today.AddDays(2), 100, 200),
                new AccountStatement(today.AddDays(1), -100, 100),
                new AccountStatement(today, 200, 200)
            };

            Check.That(balance.GetAccountStatements()).IsEqualTo(expectedStatements);
        }
예제 #2
0
        public void ShouldAddWithdrawIntoTransactions()
        {
            DateTime          today            = DateTime.Now;
            ITransactions     transactions     = Substitute.For <ITransactions>();
            IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>();
            var  bankingService = new BankingService(transactions, balanceRetriever);
            uint withdrawAmount = 200;

            bankingService.Withdraw(withdrawAmount, today);

            transactions.Received().Add(Arg.Is <ITransaction>(t => t.GetType() == typeof(Withdraw)));
        }
        public void ShouldReturnNoStatementWhenHavingNoTransaction()
        {
            DateTime                today            = DateTime.Now;
            ITransactions           transactions     = Substitute.For <ITransactions>();
            List <AccountStatement> noStatements     = new List <AccountStatement>();
            IBalanceRetriever       balanceRetriever = Substitute.For <IBalanceRetriever>();

            balanceRetriever.GetStatements().Returns(noStatements);
            var bankingService = new BankingService(transactions, balanceRetriever);

            var balance = bankingService.PrintBalance();

            Check.That(balance.GetAccountStatements()).IsEmpty();
        }
        public void ShouldReturnOneStatementWhenHavingOneWithdrawTransaction()
        {
            DateTime                today        = DateTime.Now;
            ITransactions           transactions = Substitute.For <ITransactions>();
            List <AccountStatement> statements   = new List <AccountStatement>
            {
                new AccountStatement(today, -100, -100)
            };
            IBalanceRetriever balanceRetriever = Substitute.For <IBalanceRetriever>();

            balanceRetriever.GetStatements().Returns(statements);
            var bankingService = new BankingService(transactions, balanceRetriever);

            var balance = bankingService.PrintBalance();

            Check.That(balance.GetAccountStatements())
            .ContainsExactly(new AccountStatement(today, -100, -100));
        }
예제 #5
0
 public BankingService(ITransactions transactions, IBalanceRetriever balanceRetriever)
 {
     this.transactions     = transactions;
     this.balanceRetriever = balanceRetriever;
 }