Exemple #1
0
        public void TestAddProductToCart(string productKey, Product expectProduct)
        {
            var sut      = new Homework09();
            var products = sut.GetAllProducts();
            var product  = products.FirstOrDefault(it => it.SKU == productKey);

            product.Should().BeEquivalentTo(expectProduct);
        }
Exemple #2
0
        public void TestGetAllProducts()
        {
            var sut      = new Homework09();
            var result   = sut.GetAllProducts();
            var products = GetProducts();

            result.Should().BeEquivalentTo(products);
        }
Exemple #3
0
    static void Main(string[] args)
    { //**** เหลือสร้าง display ใช่ strinbuilder *****/
        Homework09 hm9 = new Homework09();

        foreach (var value in hm9.GetAllProducts())
        {
            Console.WriteLine(value.Name);
        }
    }
Exemple #4
0
        static void Main(string[] args)
        {
            var svc = new Homework09();

            while (true)
            {
                Console.Write("Please input a product key: ");
                svc.GetProductById(Console.ReadLine());
                svc.DisplayPOS();
            }
        }
Exemple #5
0
        public void TestGetProductsInCart(List <string> productKeys, List <Product> expectProducts)
        {
            var sut      = new Homework09();
            var products = sut.GetAllProducts();

            foreach (var key in productKeys)
            {
                var product = products.FirstOrDefault(it => it.SKU == key);
                sut.AddProductToCart(product);
            }
            var productsInCart = sut.GetProductsInCart();

            productsInCart.Should().BeEquivalentTo(expectProducts);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var call          = new Homework09();
            var amount        = 0.00;
            var input         = "";
            var getAllProduct = call.GetAllProducts().ToList();

            while (true)
            {
                var productsInCart = call.GetProductsInCart().ToList();

                Console.WriteLine();
                Console.WriteLine("Products in your cart are");

                if (productsInCart.Capacity == 0)
                {
                    Console.WriteLine("none");
                }
                else
                {
                    var no = 1;

                    foreach (var item in productsInCart)
                    {
                        Console.WriteLine($"{no}.{item.SKU},{item.Name},{item.Price,2:N}");
                        no++;
                    }
                }

                Console.WriteLine("---");
                Console.WriteLine($"Total amount: {amount,2:N} baht");
                Console.Write("Please input a product key:");
                input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    break;
                }

                var addToCart = getAllProduct.Find(it => it.SKU == input);

                call.AddProductToCart(addToCart);
                amount += addToCart.Price;
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var svc = new Homework09();

            svc.CreateMockProductIfFileNotExists();

            while (true)
            {
                Console.Write(svc.GetPrintString());
                var key = Console.ReadLine();
                if (!svc.AddProductByKey(key))
                {
                    Console.WriteLine(svc.NotFoundProductText);
                }
                ;
                Console.WriteLine();
            }
        }
Exemple #8
0
    static void Main(string[] args)
    {
        var products = new List <Product>();
        // var cart = new List<Product>();

        var reader = System.IO.File.ReadAllLines(@"product.csv");
        // var tt = new StreamReader(File.OpenRead(@"D:\NO_3\product.csv"));
        // var li = tt.ReadLine
        // foreach (var item in reader)
        // {
        //     System.Console.WriteLine(item);
        // }
        var text = reader.Skip(1);

        foreach (var item in text)
        {
            var values = item.Split(','); // {SKU,Name,Price} => {p01, iPad Pro 11-inch, 23900}
            var goo    = new Product
            {
                SKU   = values[0],
                Name  = values[1],
                Price = Double.Parse(values[2])
            };
            products.Add(goo);
        }

        // var all = products.Skip(1);
        //------------------------------------
        // foreach (var item in products)
        // {
        //     Console.WriteLine(item.Name);
        // }

        // var qry = all.FirstOrDefault(it => it.SKU == "p01");
        // System.Console.WriteLine(qry.SKU);
        var cart = new Homework09();
        var key  = System.Console.ReadLine();
        var para = products.FirstOrDefault(it => it.SKU == key);

        System.Console.WriteLine(para.Name);
        System.Console.WriteLine(para.Price);
    }
Exemple #9
0
        static void Main(string[] args)
        {
            var pos      = new Homework09();
            var products = pos.GetAllProducts();

            var displayProducts = new StringBuilder();

            displayProducts.AppendLine("Current product in POS");
            displayProducts.AppendLine("\tSKU\tName\t\t\t\tPrice");
            foreach (var item in products)
            {
                displayProducts.AppendLine($"\t{item.SKU}\t{item.Name}\t\t\t{item.Price.ToString("N2")}");
            }
            var rules = $"Rules{Environment.NewLine}\tInput 'list' to display current product{Environment.NewLine}\tInput: 'exit' to exit program{Environment.NewLine}\tInput: number each SKU for add to cart";

            Console.Write($"Hello Welcome to POS analysis (HomeWork 09){Environment.NewLine}{displayProducts}{Environment.NewLine}{rules}{Environment.NewLine}");

            var isContinueInputLedOnScreen = true;

            while (isContinueInputLedOnScreen)
            {
                System.Console.WriteLine($"{new string('=', 60)}{Environment.NewLine}Products in your cart are");
                var orderProducts = pos.GetProductsInCart().ToList();
                if (orderProducts.Any())
                {
                    for (int i = 0; i < orderProducts.Count(); i++)
                    {
                        var product = orderProducts[i];
                        System.Console.WriteLine($"{i + 1}.{product.Name}\t{product.Price.ToString("N2")}");
                    }
                }
                else
                {
                    System.Console.WriteLine($"none");
                }

                System.Console.WriteLine($"---{Environment.NewLine}Total amount: {orderProducts.Sum(it => it.Price).ToString("N2")} baht");
                System.Console.Write("Please input a product key: ");

                var input = Console.ReadLine();
                switch (input)
                {
                case "exit": isContinueInputLedOnScreen = false; break;

                case "list": System.Console.WriteLine(displayProducts); break;

                default:

                    var product        = products.FirstOrDefault(it => it.SKU.Equals(input, StringComparison.CurrentCultureIgnoreCase));
                    var isProductExist = product != null;
                    if (!isProductExist)
                    {
                        System.Console.WriteLine($"Has not any product's key: {input} in POS, Please try again");
                        break;
                    }

                    pos.AddProductToCart(product);
                    break;
                }
            }
            System.Console.WriteLine("Exit program!");
        }