Ejemplo n.º 1
0
        public (bool ShirtsInStock, string Status) ServeCustomer(
            StockController controller)
        {
            var    result = controller.SelectRandomShirt();
            TShirt shirt  = result.Shirt;

            if (result.Result == SelectResult.NoStockLeft)
            {
                return(false, "All shirts sold");
            }
            else if (result.Result == SelectResult.ChosenShirtSold)
            {
                return(true, "Can't show shirt to customer - already sold");
            }

            Thread.Sleep(Rnd.NextInt(30));

            // customer chooses to buy with only 20% probability
            if (Rnd.TrueWithProb(0.2))
            {
                bool sold = controller.Sell(shirt.Code);
                if (sold)
                {
                    return(true, $"Sold {shirt.Name}");
                }
                else
                {
                    return(true, $"Can't sell {shirt.Name}:Already sold");
                }
            }
            return(true, null);
        }