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(); }
public void Deserialization_Exception_EmptyList() { FruitsList fruits = new FruitsList(); var actual = fruits.Deserialize("file.txt"); var expected = new List <Fruit>(); CollectionAssert.AreEqual(actual, expected); }
public void Deserialize_Exception_NoFileExist() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); FruitsList fruits = new FruitsList(); fruits.Deserialize(""); string expected = "Empty path name is not legal.\r\n"; string actual = sw.ToString(); sw.Close(); Assert.AreEqual(actual, expected); } }