public void PolygonService_SerializeAll_DeseriallizeAll_Test() { Polygon myPolygon = new Polygon(); myPolygon.Stroke = Brushes.Black; myPolygon.Fill = Brushes.LightSeaGreen; myPolygon.StrokeThickness = 5; Point Point1 = new Point(1, 50); Point Point2 = new Point(10, 80); Point Point3 = new Point(50, 50); PointCollection myPointCollection = new PointCollection(); myPointCollection.Add(Point1); myPointCollection.Add(Point2); myPointCollection.Add(Point3); myPolygon.Points = myPointCollection; PolygonsService ps = new PolygonsService(); ps.repo.Add(myPolygon); string path = "C:/Users/Hp/Desktop/Team_NAME/FiguresTask/UnitTests/bin/Debug/rez.txt"; ps.SerealizeAll(path); List <Polygon> polArr = (ps.DeserializeAll(path)).ToList(); Assert.AreEqual(5, polArr[0].StrokeThickness); }
/// <summary> /// Saves actual canvars /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Save() { try { SaveFileDialog saveFileWindow = new SaveFileDialog(); saveFileWindow.Filter = "Text file (*.xml)|*.xml"; Nullable <bool> result = saveFileWindow.ShowDialog(); if (saveFileWindow.FileName != string.Empty) { string[] args = saveFileWindow.FileName.Split('\\'); string title = args[args.Length - 1]; Title = title; string path2 = System.IO.Path.GetFullPath(saveFileWindow.FileName); service.SerealizeAll(path2); path = path2; SaveButton.Command = new SaveCommand { canExecute = true }; } if (result == false) { close = false; } else { close = true; } } catch (Exception ex) { throw new ArgumentException(ex.ToString()); } }