示例#1
0
        /// <summary>
        /// This Method provides the opportunity to buy <see cref="Stock"/> and thereby adding it to a selected <see cref="Portfolio"/>
        /// <see cref="Stock"/> is automatically set to GOOGLE
        /// </summary>
        /// <param name="portfolio">Chosen portfolio to buy stock to</param>
        public static void BuyStock(IPortfolio portfolio)
        {
            Console.WriteLine("-- StockMarket --");
            Console.WriteLine("Buy stock");
            Console.WriteLine("Type the name of the stock to Select");
            foreach (var stockItem in Stocks)
            {
                Console.WriteLine($"{stockItem.Name} | {stockItem.Value}");
            }

            Console.WriteLine();
            var input = Console.ReadLine();

            input = "Google";

            foreach (var stockItem in Stocks)
            {
                if (input == stockItem.Name)
                {
                    Console.WriteLine("How many would you like to buy?");
                    var inputAmount = Console.ReadLine();

                    Int32.TryParse(inputAmount, out int result);

                    // Adds the specific amount of Stock
                    if (inputAmount != null)
                    {
                        portfolio.AddStock((Stock)stockItem, result);
                    }
                    Console.WriteLine("Transaction was successful");
                    return;
                }
            }

            Console.WriteLine("The typed stock name wasn't valid, try again");
        }
 public void Portfolio_Total_returns1()
 {
     _uut.AddStock(_stock, 1);
     Assert.That(_uut.Total, Is.EqualTo(1));
 }