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 CanGetProductList() { FileProductRepository repo = new FileProductRepository(filePath); List <Product> products = repo.GetProductList(); Assert.IsNotNull(products); }
public void SearchFirstProductsNameFail() { IProductRepository productRepository = new FileProductRepository(); List <Product> products = productRepository.GetAll(); string temp = products[0].Name; Assert.NotEqual("Apple", temp); }
public void LoadProducts() { string _path2file = @"C:\Data\Products.txt"; FileProductRepository data = new FileProductRepository(_path2file); List <Products> products = data.ListProducts(); Assert.AreEqual("Wood", products[3].ProductType); Assert.AreEqual(5.15, products[3].CostPerSquareFoot); Assert.AreEqual(4.75, products[3].LaborCostPerSquareFoot); Assert.AreEqual(4, products.Count()); }
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); }
public static IProducts CreateProductRepository() { string mode = ConfigurationManager.AppSettings["Mode"].ToString(); IProducts repo; switch (mode.ToUpper()) { case "TEST": repo = new InMemoryProductRepository(); break; case "PROD": repo = new FileProductRepository(); break; default: throw new Exception("No such repository, check your settings"); } return(repo); }
public OrderResponse AddOrder(DateTime date) { OrderResponse response = new OrderResponse(); if (date < DateTime.Today) { response.Success = false; response.Message = $"{date} is not valid. Please enter a future date."; return(response); } else { response.Success = true; } Order order = new Order(); order.OrderDate = date; order.OrderFileDate = date.ToString("MMddyyyy"); do { Console.Write("Enter Customer Name: "); order.CustomerName = Console.ReadLine(); } while (order.CustomerName == ""); do { Console.Write("Enter State Abbreviation: "); order.State = Console.ReadLine().ToUpper(); } while (order.State == "" || order.State.Length != 2); ReadTaxData readTax = new ReadTaxData(); //check state.txt readTax.InRepo(order.State); if (!readTax.InRepo(order.State)) { response.Message = "We do not sell in that state!"; response.Success = false; return(response); } else { Tax stateTax = new Tax(); stateTax = readTax.StateTax(order.State); order.TaxRate = (stateTax.TaxRate / 100); } Product newProduct = new Product(); do { //print list of products with foreach loop //DisplayProducts display = new DisplayProducts(); //display.Show(); FileProductRepository prodRepo = new FileProductRepository(); prodRepo.DisplayProducts(); //Console.Write("Enter a choice from the list above: "); //add validation newProduct = prodRepo.ChooseProduct(); order.ProductType = newProduct.ProductType; order.CostPerSquareFoot = newProduct.CostPerSquareFoot; order.LaborCostPerSquareFoot = newProduct.LaborCostPerSquareFoot; } while (order.ProductType != newProduct.ProductType); while (order.Area <= 100) { decimal orderArea; Console.Write("Enter the area of the order in square feet (greater than 100 sqft): "); string input = Console.ReadLine(); if (decimal.TryParse(input, out orderArea)) { order.Area = orderArea; } } order.LaborCost = order.LaborCostPerSquareFoot * order.Area; order.MaterialCost = order.CostPerSquareFoot * order.Area; order.Tax = (order.LaborCost + order.MaterialCost) * order.TaxRate; order.Total = order.LaborCost + order.MaterialCost + order.Tax; response.Success = true; response.Order = order; //order = response.Order; //IOrder newOrder = OrderRulesFactory.Create(ChangeOrder.Add); // response = newOrder.Update(order, order.OrderDate); //if(response.Success) //{ // _displayOrder.Show(order); // Console.Write("Save this order (Y/N)? "); // string saveOrder = Console.ReadLine().ToUpper(); // if (saveOrder == "Y") // { // _orderRepository.SaveOrder(order, order.OrderFileDate); // Console.WriteLine(); // Console.WriteLine("Order saved!"); // response.Success = true; // } //} return(response); }
public OrderResponse EditOrder(DateTime date, int orderNumber) { OrderResponse response = new OrderResponse(); Order order = new Order(); //if (date > DateTime.Today) //{ // response.Success = false; // response.Message = $"{date} is not valid. Please enter a past date."; // return response; //} if (orderNumber < 1) { response.Success = false; response.Message = "You must enter a valid order number!"; return(response); } else { response.Success = true; } OrderLookupResponse findOrderResponse = new OrderLookupResponse() { Order = _orderRepository.LoadOrder(date, orderNumber) }; if (findOrderResponse.Order == null) { findOrderResponse.Success = false; findOrderResponse.Message = $"{orderNumber} is not a valid order number!"; } else { findOrderResponse.Success = true; } if (findOrderResponse.Success) { order = findOrderResponse.Order; order.OrderFileDate = order.OrderDate.ToString("MMddyyyy"); string editField = "To change value, edit here (to keep, press Enter): "; Console.WriteLine($"Customer Name: {order.CustomerName}"); Console.Write(editField); string input = Console.ReadLine(); if (input != "") { order.CustomerName = input; } Console.WriteLine($"State Abbreviation: {order.State}"); Console.Write(editField); input = Console.ReadLine(); if (input != "") { order.State = input.ToUpper(); } ReadTaxData readTax = new ReadTaxData(); //check state.txt readTax.InRepo(order.State); if (!readTax.InRepo(order.State)) { response.Message = "We do not sell in that state!"; return(response); } else { Tax stateTax = new Tax(); stateTax = readTax.StateTax(order.State); order.TaxRate = (stateTax.TaxRate / 100); } Console.WriteLine($"Product: {order.ProductType}"); Console.Write("Would you like to change your product? (Y/N): "); input = Console.ReadLine(); if (input == "Y") { Product newProduct = new Product(); //print list of products with foreach loop FileProductRepository prodRepo = new FileProductRepository(); prodRepo.DisplayProducts(); //Console.Write("Enter a choice from the list above: "); newProduct = prodRepo.ChooseProduct(); order.ProductType = newProduct.ProductType; order.CostPerSquareFoot = newProduct.CostPerSquareFoot; order.LaborCostPerSquareFoot = newProduct.LaborCostPerSquareFoot; } Console.WriteLine($"Order Area: {order.Area}"); Console.Write(editField); input = Console.ReadLine(); if (input != "") { order.Area = -1; while (order.Area < 100) { decimal orderArea; if (decimal.TryParse(input, out orderArea)) { order.Area = orderArea; } if (order.Area < 100) { Console.WriteLine($"Order Area: {order.Area}"); Console.Write(editField); input = Console.ReadLine(); } } } order.LaborCost = order.LaborCostPerSquareFoot * order.Area; order.MaterialCost = order.CostPerSquareFoot * order.Area; order.Tax = (order.LaborCost + order.MaterialCost) * order.TaxRate; order.Total = order.LaborCost + order.MaterialCost + order.Tax; response.Success = true; response.Order = order; //IOrder editOrder = OrderRulesFactory.Create(ChangeOrder.Edit); //Order foundOrder = new Order(); //foundOrder = findOrderResponse.Order; //response = editOrder.Update(foundOrder, date); //if (response.Success) //{ // _displayOrder.Show(order); // Console.Write("Save this order (Y/N)? "); // string saveOrder = Console.ReadLine().ToUpper(); // if (saveOrder == "Y") // { // _orderRepository.SaveOrder(order, order.OrderFileDate); // Console.WriteLine(); // Console.WriteLine("Order saved!"); // response.Success = true; // } //} } return(response); }
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); }