Ejemplo n.º 1
0
        /// <summary>
        /// This Method provides the opportunity to Sell <see cref="Stock"/> and thereby remove it from a selected <see cref="Portfolio"/>
        /// <see cref="Stock"/> is automatically set to GOOGLE
        /// </summary>
        /// <param name="portfolio">Chosen portfolio to sell stock from</param>
        public static void SellStock(IPortfolio portfolio)
        {
            // If stock is not initialized return. could be implemented with an exception
            if (Stocks == null)
            {
                return;
            }

            Console.WriteLine("-- StockMarket --");
            Console.WriteLine("Sell your stock");
            Console.WriteLine("Type the name of the stock to Select");

            foreach (var stockItem in portfolio.Stocks)
            {
                Console.WriteLine($"{stockItem.Key.Name} | {stockItem.Value}");
            }

            Console.WriteLine("--- ");
            Console.WriteLine();

            // Takes input from user.
            string input = Console.ReadLine();

            input = "Google";

            foreach (var stockItem in portfolio.Stocks.Keys)
            {
                if (input != stockItem.Name)
                {
                    continue;
                }

                Console.WriteLine("How many would you like to sell?");
                var inputAmount = Console.ReadLine();

                Int32.TryParse(inputAmount, out int result);

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

            Console.WriteLine("The typed stock name wasn't valid, try again");
        }
Ejemplo n.º 2
0
 public void Portfolio_RemoveStock_NonEmpty()
 {
     _uut.AddStock(_stock, 2);
     _uut.RemoveStock(_stock, 1);
     Assert.IsTrue(_uut.Stocks.ContainsKey(_stock));
 }