public CommandReturnCode Process(string[] args) { responseBuffer.Length = 0; if (args.Length == 2) { Debug.Assert(args[0].Equals("get-item", StringComparison.OrdinalIgnoreCase)); int id; var isIdValid = int.TryParse(args[1], out id); if (isIdValid) { isIdValid = productCatalog.IsExist(id); if (isIdValid) { Product product = productCatalog.GetItem(id); responseBuffer.Append($"Product Id = {product.Id}\nName={product.Name}\nPrice={product.Price}\nCount={product.Count}\nUnit={product.Unit}"); 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); }
public CommandReturnCode Process(string[] args) { responseBuffer.Length = 0; if (args.Length == 2) { Debug.Assert(args[0].Equals("delete", StringComparison.OrdinalIgnoreCase)); int id; var isIdValid = int.TryParse(args[1], out id); if (isIdValid) { isIdValid = productCatalog.IsExist(id); if (isIdValid) { productCatalog.Delete(id); responseBuffer.Append(string.Format("Product with Id = \"{0}\" has been successfully deleted", id)); 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); }
public CommandReturnCode Process(string[] args) { responseBuffer.Length = 0; if (args.Length == 3) { Debug.Assert(args[0].Equals("sub-count", StringComparison.OrdinalIgnoreCase)); int id; var isIdValid = int.TryParse(args[1], out id); if (isIdValid) { int countToSubstract; var isCountToASubstractValid = int.TryParse(args[2], out countToSubstract) && countToSubstract > 0; if (isCountToASubstractValid) { isIdValid = productCatalog.IsExist(id); if (isIdValid) { try { productCatalog.SubstractCount(id, countToSubstract); responseBuffer.Append(string.Format( "Specified amount ({0}) has been successfully substracted from \"Count\" of product with Id = \"{1}\"", countToSubstract, id)); responseBuffer.Append(Environment.NewLine); } catch (InvalidOperationException) { responseBuffer.Append("Cannot substract specified amount"); 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); }
public void DoesProductExistCatalogTests() { Product product = new Toy(); product.Name = "Barbie3"; product.Count = 10; product.Price = 9999; product.Unit = "Шт"; productTestCatalog.Add(product); bool isExist; isExist = productTestCatalog.IsExist(0); ///Проверка IsExist Assert.True(isExist); }
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); }