public void CountNumberOfProductsInCsv() { IProductRepository productRepository = new FileProductRepository(); List <Product> products = productRepository.GetAll(); Assert.Equal(12, products.Count); }
static void Main(string[] args) { IProductRepository productRepository = new FileProductRepository(); var products = productRepository.GetAll(); Console.WriteLine("Product Manager Project in C#\r"); Menu(); string inputValue = Console.ReadLine(); while (inputValue != "q") { switch (inputValue) { case "1": ShowAllProducts(products); inputValue = Console.ReadLine(); break; case "2": SearchProductMinPrice(products); inputValue = Console.ReadLine(); break; case "3": AddProductWithUsersParameters(products, productRepository); inputValue = Console.ReadLine(); break; case "4": DeleteProduct(products, productRepository); inputValue = Console.ReadLine(); break; case "5": SearchProductByName(products); inputValue = Console.ReadLine(); break; case "6": ShowProducersAndTheirProducts(products); inputValue = Console.ReadLine(); break; case "7": IShopsRepository shopsRepository = new ShopsRepository(); shopsRepository.ShowProductsInEachShop(products); inputValue = Console.ReadLine(); break; case "q": break; default: Console.WriteLine("This option is not defined. Try again!"); inputValue = Console.ReadLine(); break; } } }
public void SearchFirstProductsNameFail() { IProductRepository productRepository = new FileProductRepository(); List <Product> products = productRepository.GetAll(); string temp = products[0].Name; Assert.NotEqual("Apple", temp); }
//Handling input in ProductMenu--------------------------------------------------------------------------------- private static void AddProduct() { Console.WriteLine("Please enter a product name."); var userInput = GetUserInputString(); Console.WriteLine("Please enter a product price."); var inputDecimal = GetUserInputDecimal(); var inputInt = 0; if (_manufacturers.ManufacturersList.Count > 0) { Console.WriteLine( "Please choose a manufacturer from the list below or type 0 to add a new manufacturer."); ListItems(_manufacturers.ManufacturersList); inputInt = GetUserInputInt(_manufacturers.ManufacturersList.Count, 0); } else if (_manufacturers.ManufacturersList.Count == 0) { Console.WriteLine("No manufacturers on file. You can create one now."); } if (inputInt == 0) { AddManufacturerProductMenu(); _products.Insert(userInput, inputDecimal, _manufacturers.ManufacturersList.Last()); } else { _products.Insert(userInput, inputDecimal, _manufacturers.ManufacturersList[inputInt - 1]); } Console.WriteLine($"Product Added \n{_products.GetAll().Last()}"); _manufacturers.Save(_manufacturers.ManufacturerJsonPath, _manufacturers.ManufacturersList); _products.Save(_products.ProductJsonPath, _products.ProductList); Enter(); }
public void CheckListOfProductFromCSVFile() { IProductRepository productRepository = new FileProductRepository(); var products = productRepository.GetAll(); List <string> productNameCsv = new List <string>(); foreach (var prod in products) { productNameCsv.Add(prod.Name); } var test = new List <string>() { "Milk", "Shampoo", "Chocolate Bar", "Cucumber", "Potato", "Coca-Cola", "Banan", "Ananas", "Beef", "Dog's Food", "Liquid Soap", "Tomato" }; CollectionAssert.AreEqual(productNameCsv, test); }
static void Main() { ProductFilter productFilter = new ProductFilter(); int choice = 0; do { Clear(); WriteLine("1. List all items"); WriteLine("2. Add New Product"); WriteLine("3. Find Product"); WriteLine("4. Delete Product"); WriteLine("5. Update Product"); WriteLine("6. Find ManuFacturer"); WriteLine("7. Find By Price"); WriteLine("8. List all Shops"); WriteLine("9. Exit"); Write("Please, Select a Number from 1 to 9: "); int.TryParse(ReadLine(), out choice); // switch (choice) { // Case 1 : Option For List case 1: new FileProductRepository().GetAll(); break; // Case 2 : Option For Add case 2: IProductRepository productRepository = new FileProductRepository(); var product = ConsoleHelper.NewProduct(); productRepository.Insert(product); break; // Case 3 : Option For Find case 3: //ProductFilter.GetByProductName(); IProductRepository productFindRep = new FileProductRepository(); WriteLine("Product Name :"); var productToFind = ReadLine(); product = productFindRep.GetByProductName(productToFind); if (product != null) { WriteLine("Product Find ... \n Please Press Enter To Go Back "); } else { WriteLine("Product Not found... \n Please Press Enter To Go Back "); } ReadLine(); break; // Case 4 : Option For Delete case 4: IProductRepository productDeleteRep = new FileProductRepository(); WriteLine("Product Name : "); var productToDelete = ReadLine(); product = productDeleteRep.GetByProductName(productToDelete); if (product != null) { productDeleteRep.Delete(product); WriteLine("Product Delete... \n Please Press Enter To Go Back "); } else { WriteLine("Product Not found... \n Please Press Enter To Go Back "); } ReadLine(); break; // Case 5: Option For Updata case 5: IProductRepository productUploadRep = new FileProductRepository(); WriteLine("Product Name For Upload : "); var productToUpload = ReadLine(); product = productUploadRep.GetByProductName(productToUpload); if (product != null) { WriteLine("Product Name :"); product.Name = ReadLine(); WriteLine("Please enter Price (,) : "); product.Price = decimal.Parse(ReadLine()); WriteLine("Product ManuFacturer :"); product.ManuFacturer = ReadLine(); productUploadRep.Upload(product); } else { WriteLine("Product Not found... \n Please Press Enter To Go Back "); } break; case 6: IProductRepository productFindManu = new FileProductRepository(); WriteLine("ManuFacturer Name :"); var productToFindManu = ReadLine(); product = productFindManu.GetByManuFacturerName(productToFindManu); if (product != null) { WriteLine("ManuFacturer Find ... \n Please Press Enter To Go Back "); } else { WriteLine("ManuFacturer Not found... \n Please Press Enter To Go Back "); } ReadLine(); break; case 7: IProductRepository productFindPrice = new FileProductRepository(); WriteLine("Write Price :"); try { var maxPrice = decimal.Parse(ReadLine()); if (maxPrice > 0) { productFilter.SearchByPrice(maxPrice, productFindPrice.GetAll()); } else { throw new FormatException(); } } catch (FormatException) { WriteLine("Invalid input"); } WriteLine("\nPlease Press Enter To Go Back"); ReadLine(); break; case 8: new FileShopRepository().GetAll(); break; } } while (choice != 9); }