private static void Scan()
        {
            StockEngine engine = new YahooStockEngine();

            IEnumerable<string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            //IEnumerable<Quote> stocks = engine.LookupPrices(symbols); // Get everything
            string[] playerNames = engine.GetAllPlayers().Select(x => x.Name).ToArray();

            IEnumerable<Quote> stocks = engine.LookupQuotesForPlayers(playerNames);
            if (stocks.Count() < 1 || stocks.Any(s => s == null))
            {
                // Try Google
                Log.Information("No stocks found - switching to the Google API");
                engine = new GoogleStockEngine();
                symbols = engine.LoadSymbolsFromTextFile("aim.txt");
                stocks = engine.LookupQuotesForPlayers(playerNames);
            }

            engine.InsertQuotes(stocks);
            Log.Information("Saved {0} new stock prices to the database.", stocks.Count());

            //
            // Calculate if investments should be sold for each players
            //
            foreach (Player player in engine.GetAllPlayers())
            {
                Quote quote = engine.GetCurrentQuoteForPlayer(player.Name);
                Investment investment = engine.GetCurrentInvestmentForPlayer(player.Name);
                if (player.ShouldSellInvestment(quote, investment))
                {
                    // Sell sell sell
                    Log.Information("Selling {0}'s investment in {1} - ({2}) current price is {3}", player.Name, investment.Symbol, investment.SellReason, quote.LastTradePrice.Value);
                    engine.SellInvestment(investment.Id, quote.LastTradePrice.Value, investment.SellReason.Value, DateTime.Now);

                    // Buy buy buy
                    string nextSymbol = engine.PickRandomSymbol(symbols);
                    Quote nextQuote = engine.LookupPrice(nextSymbol);
                    engine.InitializePlayer(player, nextQuote, 400);
                    Log.Information("New investment set up for {0}. Bought {1} shares in {2} at price of {3}", player.Name, investment.Quantity, quote.Symbol, quote.LastTradePrice.Value);
                }
            }
        }
        public void GetCurrentQuoteForPlayer()
        {
            // Arrange
            StockEngine engine = new YahooStockEngine();
            IEnumerable<string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string randomSymbol = engine.PickRandomSymbol(symbols);
            Quote quote = engine.LookupPrice(randomSymbol);
            decimal walletSize = 400; // £400

            Player player = new Chris();

            // Act
            engine.InsertQuote(quote);
            engine.InitializePlayer(player, quote, walletSize);
            Quote currentQuote = engine.GetCurrentQuoteForPlayer(player.Name);

            // Assert
            Assert.That(currentQuote.Id, Is.EqualTo(quote.Id));
            Assert.That(currentQuote.Symbol, Is.EqualTo(quote.Symbol));
            Assert.That(currentQuote.LastTradePrice, Is.EqualTo(quote.LastTradePrice));
        }
        public void GetPlayerHistory()
        {
            // Arrange
            StockEngine engine = new YahooStockEngine();
            IEnumerable<string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string randomSymbol = engine.PickRandomSymbol(symbols);
            decimal walletSize = 400;

            Player player = new Chris();
            Quote quote1 = engine.LookupPrice(randomSymbol);
            engine.InitializePlayer(player, quote1, walletSize);

            Quote quote2 = engine.LookupPrice(randomSymbol);
            engine.InitializePlayer(player, quote2, walletSize);

            // Act
            IEnumerable<Investment> investments = engine.GetInvestmentHistoryForPlayer(player.Name);

            // Assert
            Assert.That(investments.Count(), Is.EqualTo(2));
        }
        public void InitializePlayer()
        {
            // Arrange
            StockEngine engine = new YahooStockEngine();
            IEnumerable<string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string randomSymbol = engine.PickRandomSymbol(symbols);
            Quote quote = engine.LookupPrice(randomSymbol);
            decimal walletSize = 400; // £400

            Player player = new Chris();

            // Act
            engine.InsertQuote(quote);
            engine.InitializePlayer(player, quote, walletSize);

            // Assert
            Investment investment = engine.GetCurrentInvestmentForPlayer(player.Name);
            Assert.That(investment.Symbol, Is.EqualTo(randomSymbol));
            Assert.That(investment.PlayerName, Is.EqualTo(player.GetType().Name));
            Assert.That(investment.PurchaseDate, Is.GreaterThan(DateTime.Today));
            Assert.That(investment.PurchasePrice, Is.EqualTo(quote.LastTradePrice.Value));
        }
        public void PickRandomSymbol()
        {
            // Arrange
            StockEngine engine = new YahooStockEngine();

            // Act
            IEnumerable<string> symbols = engine.LoadSymbolsFromTextFile("aim.txt");
            string randomSymbol = engine.PickRandomSymbol(symbols);

            // Assert
            Console.WriteLine("Picked: {0}", randomSymbol);
            Assert.IsNotNullOrEmpty(randomSymbol);
        }