Beispiel #1
0
        public void GetFoodProductOutput()
        {
            //arrange
            string   testItemBrand               = "Oleyna";
            string   testItemModel               = "V2";
            DateTime testItemProductionDate      = new DateTime(2020, 2, 2);
            string   testItemFoodType            = "Oil";
            DateTime testItemSuitabilityDuration = new DateTime(2020, 4, 4);
            var      expected = "Brand: Oleyna Model: V2 ProductionDate: 02.02.2020 Food type: Oil Suitability Duraion: 04.04.2020";

            //act
            var actual = new FoodProduct()
            {
                Brand = testItemBrand, Model = testItemModel, ProductionDate = testItemProductionDate, FoodType = testItemFoodType, SuitabilityDuration = testItemSuitabilityDuration
            }.ToString();

            //assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public void GetExpirationDate()
        {
            //arrange
            string   testItemBrand               = "Oleyna";
            string   testItemModel               = "V2";
            DateTime testItemProductionDate      = new DateTime(2020, 2, 2);
            string   testItemFoodType            = "Oil";
            DateTime testItemSuitabilityDuration = new DateTime(2021, 2, 2);
            var      expected = testItemSuitabilityDuration;

            //act
            var testItem = new FoodProduct()
            {
                Brand = testItemBrand, Model = testItemModel, ProductionDate = testItemProductionDate, FoodType = testItemFoodType, SuitabilityDuration = testItemSuitabilityDuration
            };
            var actual = testItem.GetExpirationDate();

            //assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void GetExpiredFoodProducts()
        {
            //arrange
            string   testItemBrand               = "Oleyna";
            string   testItemModel               = "V2";
            DateTime testItemProductionDate      = new DateTime(2020, 2, 2);
            string   testItemFoodType            = "Oil";
            DateTime testItemSuitabilityDuration = new DateTime(2020, 4, 4);
            var      expected = new List <Product>().ToString();

            //act
            var testItem = new FoodProduct()
            {
                Brand = testItemBrand, Model = testItemModel, ProductionDate = testItemProductionDate, FoodType = testItemFoodType, SuitabilityDuration = testItemSuitabilityDuration
            };
            var testItemList = new List <Product>();

            testItemList.Add(testItem);
            var actual = Program.GetExpiredProducts(testItemList).ToString();


            //assert
            Assert.AreEqual(expected, actual);
        }
Beispiel #4
0
        static void Main()
        {
            const string XMLFilePath = @"C:\Users\Sevka\source\repos\ProductsApp\ProductsApp\OutputXML.xml";
            const string filePath    = @"C:\Users\Sevka\source\repos\ProductsApp\ProductsApp\Output.txt";
            var          products    = new List <Product>();

            Console.WriteLine("Please enter items (first element product, second element FoodProduct): ");

            var p1 = new Product();

            p1.Input();
            products.Add(p1);

            var p2 = new Product()
            {
                Brand = "Nike", Model = "AirForce", ProductionDate = new DateTime(2020, 2, 2)
            };

            products.Add(p2);

            var p3 = new Product()
            {
                Brand = "Apple", Model = "IPhone11", ProductionDate = new DateTime(2021, 3, 3)
            };

            products.Add(p3);


            var fp1 = new FoodProduct();

            fp1.Input();
            products.Add(fp1);

            var fp2 = new FoodProduct()
            {
                Brand = "Molokiia", Model = "3.5%", ProductionDate = new DateTime(2022, 3, 3), FoodType = "Milk", SuitabilityDuration = new DateTime(2022, 4, 4)
            };

            products.Add(fp2);

            var fp3 = new FoodProduct()
            {
                Brand = "Pepsi", Model = "Zero", ProductionDate = new DateTime(2021, 5, 5), FoodType = "Soda", SuitabilityDuration = new DateTime(2022, 5, 5)
            };

            products.Add(fp3);



            do
            {
                Console.WriteLine("What are u gonna to do? 0-Output data, 1-Output to file, 2-Serialize data, 3-Deserialize data, 4-Show Expired Products,5-SordByBrand, 6-SordByModel, 7-Exit\r\n");
                var userChoice = Convert.ToInt32(Console.ReadLine());
                switch ((UserChoice)userChoice)
                {
                case UserChoice.OutputToConsole:
                    Output(products);
                    break;

                case UserChoice.OutputToFile:
                    OutputToFile(products, filePath);
                    break;

                case UserChoice.Serialize:
                    OutputToFileXML(products, XMLFilePath);
                    break;

                case UserChoice.Deserialize:
                    DeserializeXML(XMLFilePath);
                    break;

                case UserChoice.ExpiredProducts:
                    Console.WriteLine("Expired products:\r\n ");
                    Output(GetExpiredProducts(products));
                    break;

                case UserChoice.SortByBrand:
                    var sortedByBrand = products.OrderBy(x => x.Brand);
                    Output(sortedByBrand.ToList());
                    break;

                case UserChoice.SortByModel:
                    var sortedByModel = products.OrderBy(x => x.Model);
                    Output(sortedByModel.ToList());
                    break;

                case UserChoice.Exit:
                    Environment.Exit(0);
                    break;

                default:
                    Console.WriteLine("Try again, uknown operation!");
                    break;
                }
            } while (true);
        }