Beispiel #1
0
        public void Start()
        {
            Console.WriteLine("Enter a stock symbol (for example aapl):");
            string symbol = Console.ReadLine();

            Console.WriteLine("Enter the maximum price you are willing to pay: ");
            double price;

            while (!double.TryParse(Console.ReadLine(), out price))
            {
                Console.WriteLine("Please enter a number.");
            }

            try {
                bool purchased = _trader.Buy(symbol, price);
                if (purchased)
                {
                    _logger.Log("Purchased stock!");
                }
                else
                {
                    _logger.Log("Couldn't buy the stock at that price.");
                }
            } catch (Exception e) {
                _logger.Log("There was an error while attempting to buy the stock: " + e.Message);
            }
            Console.ReadLine();
        }
Beispiel #2
0
        [Test] // Bid was lower than price, Buy() should return false.
        public void TestBidLowerThanPrice()
        {
            var result = trader.Buy("aapl", 50);

            Assert.IsFalse(result);
        }