Пример #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);
        }
Пример #2
0
        public void TestGetAllProducts()
        {
            var sut      = new Homework09();
            var result   = sut.GetAllProducts();
            var products = GetProducts();

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

        foreach (var value in hm9.GetAllProducts())
        {
            Console.WriteLine(value.Name);
        }
    }
Пример #4
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);
        }
Пример #5
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;
            }
        }
Пример #6
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!");
        }