Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            FruitsList fruitsList = new FruitsList();

            fruitsList.FillWithData();

            Console.WriteLine("\t\t\tFunction Find(string keyColor) with parametr Orange");
            fruitsList.Find("orange");
            Console.WriteLine("\n\n");

            try
            {
                using (StreamReader sr = new StreamReader(GetPath("IntputFruits.txt"), System.Text.Encoding.Default))
                {
                    while (sr.EndOfStream != true)
                    {
                        Fruit fruit = new Fruit();
                        fruit.Input(sr);
                        fruitsList.fruits.Add(fruit);
                    }
                }
            }catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            try
            {
                using (StreamReader sr = new StreamReader(GetPath("IntputCitrus.txt"), System.Text.Encoding.Default))
                {
                    while (sr.EndOfStream != true)
                    {
                        Citrus fruit = new Citrus();
                        fruit.Input(sr);
                        fruitsList.fruits.Add(fruit);
                    }
                }
            }catch (FileNotFoundException e)
            {
                Console.WriteLine(e.Message);
            }

            fruitsList.Sort();

            fruitsList.OutputToFile(GetPath("Output.txt"));

            fruitsList.Serialize(fruitsList.fruits, GetPath("Fruits.xml"));

            List <Fruit> fruitsDeserialized = fruitsList.Deserialize(GetPath("Fruits.xml"));

            Console.WriteLine("\n\n\t\tList after deserialization\n\n");

            foreach (var item in fruitsDeserialized)
            {
                item.Print();
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public void OutputToFile_Exception_NoFileExist()
        {
            using (StringWriter sw = new StringWriter())
            {
                Console.SetOut(sw);

                FruitsList fruits = new FruitsList();
                fruits.OutputToFile("");

                string expected = "Empty path name is not legal.\r\n";
                string actual   = sw.ToString();
                sw.Close();

                Assert.AreEqual(actual, expected);
            }
        }