Exemplo n.º 1
0
        public void AddProductCountCatalogTests()
        {
            Product product = new Toy();

            product.Name  = "Barbie1";
            product.Count = 10;
            product.Price = 9999;
            product.Unit  = "Шт";
            productTestCatalog.Add(product);

            ///Проверка AddCount
            productTestCatalog.AddCount(0, 90);
            Assert.AreEqual(productTestCatalog.Get(0).Count, 100);
        }
        public CommandReturnCode Process(string[] args)
        {
            responseBuffer.Length = 0;
            if (args.Length == 3)
            {
                Debug.Assert(args[0].Equals("add-count", StringComparison.OrdinalIgnoreCase));

                int id;
                var isIdValid = int.TryParse(args[1], out id);
                if (isIdValid)
                {
                    int countToAdd;
                    var isCountToAddValid = int.TryParse(args[2], out countToAdd) && countToAdd > 0;
                    if (isCountToAddValid)
                    {
                        isIdValid = productCatalog.IsExist(id);
                        if (isIdValid)
                        {
                            productCatalog.AddCount(id, countToAdd);
                            responseBuffer.Append(
                                $"\"Count\" of product with Id = {id} increased by {countToAdd}");
                            responseBuffer.Append(Environment.NewLine);
                        }
                    }
                    else
                    {
                        responseBuffer.Append(string.Format("\"count\" must be an integer number from 0 to {0}",
                                                            int.MaxValue));
                        responseBuffer.Append(Environment.NewLine);
                    }
                }

                if (!isIdValid)
                {
                    responseBuffer.Append(string.Format("Product with Id = \"{0}\" does not exist", args[1]));
                    responseBuffer.Append(Environment.NewLine);
                }
            }
            else
            {
                responseBuffer.Append(usage);
            }

            return(CommandReturnCode.Done);
        }