Exemplo n.º 1
0
        public void BalanceAfterLastTransaction()
        {
            var account = new CashAccount();

            account.Deposit(new Date(2000, 01, 01), 100.00m, "");
            account.Deposit(new Date(2000, 02, 01), 200.00m, "");
            account.Withdraw(new Date(2000, 03, 01), 50.00m, "");

            account.Balance(new Date(2002, 01, 01)).Should().Be(250.00m);
        }
Exemplo n.º 2
0
        public void BalanceAtSpecificDateWithNoTransactions()
        {
            var account = new CashAccount();

            account.Deposit(new Date(2000, 01, 01), 100.00m, "");
            account.Deposit(new Date(2000, 02, 01), 200.00m, "");
            account.Withdraw(new Date(2000, 03, 01), 50.00m, "");

            account.Balance(new Date(2000, 02, 15)).Should().Be(300.00m);
        }
Exemplo n.º 3
0
        public void BalanceNoTransactionsOnThatDate()
        {
            var account = new CashAccount();

            account.Deposit(new Date(2000, 01, 01), 100.00m, "");
            account.Deposit(new Date(2000, 02, 01), 200.00m, "");
            account.Deposit(new Date(2000, 02, 01), 60.00m, "");
            account.Withdraw(new Date(2000, 03, 01), 50.00m, "");

            account.Balance(new Date(2000, 02, 15)).Should().Be(360.00m);
        }
Exemplo n.º 4
0
        public void Withdrawl()
        {
            var account = new CashAccount();

            account.Withdraw(new Date(2000, 01, 01), 100.00m, "test");

            var result = account.Transactions.ToArray();

            result.Should().BeEquivalentTo(new[]
            {
                new { Date = new Date(2000, 01, 01), Description = "test", Amount = -100.00m, Type = BankAccountTransactionType.Withdrawl, Balance = -100.00m }
            });
        }
Exemplo n.º 5
0
        public void EffectiveBalancesStartAndEndDatesNotMatching()
        {
            var account = new CashAccount();

            account.Deposit(new Date(2000, 01, 01), 100.00m, "");
            account.Deposit(new Date(2000, 02, 01), 200.00m, "");
            account.Deposit(new Date(2000, 02, 01), 60.00m, "");
            account.Withdraw(new Date(2000, 03, 01), 50.00m, "");

            var result = account.EffectiveBalances(new DateRange(new Date(2000, 01, 15), new Date(2000, 02, 15))).ToArray();

            var expectedResult = new CashAccountEffectiveBalance[]
            {
                new CashAccountEffectiveBalance(new Date(2000, 01, 15), new Date(2000, 01, 31), 100.00m),
                new CashAccountEffectiveBalance(new Date(2000, 02, 01), new Date(2000, 02, 15), 360.00m),
            };

            result.Should().BeEquivalentTo(expectedResult);
        }
Exemplo n.º 6
0
        public void Buy(string tickerSymbol, int shares)
        {
            CashAccount account       = new CashAccount(_accountNumber);
            var         equityFactory = EquityFactory.GetInstance();
            Equity      equity        = equityFactory.CreateEquity(tickerSymbol);

            decimal amount  = equity.GetPrices() * shares;
            decimal balance = account.GetAccountBalance();

            if (balance >= amount)
            {
                account.Withdraw(amount);

                equity.Buy(shares);
                Console.WriteLine("Succesfully bought {0} {1} shares", shares, tickerSymbol);
                Console.WriteLine("New account balance is ${0}", account.GetAccountBalance());
            }
            else
            {
                Console.WriteLine("Insufficient balance ${0}", balance);
            }
        }