public void DeserializeSerialize_Format() { MindMapSerializer s = new MindMapSerializer(); MapTree tree = new MapTree(); new MapNode(tree, "root"); tree.DefaultFormat = new NodeFormat(Color.Brown, true, Color.DarkGoldenrod, FontFamily.GenericMonospace.Name, 12, true, true, Color.Red, DashStyle.Dot, 4, NodeShape.Box); tree.CanvasBackColor = Color.Cyan; tree.NoteBackColor = Color.Crimson; tree.NoteForeColor = Color.Coral; tree.SelectedOutlineColor = Color.DarkOrchid; tree.DropHintColor = Color.DarkSalmon; string serializedText; using (MemoryStream stream = new MemoryStream()) { s.Serialize(stream, tree); stream.Position = 0; serializedText = new StreamReader(stream).ReadToEnd(); } var tree2 = new MapTree(); s.Deserialize(serializedText, tree2); Assert.AreEqual(tree.DropHintColor, tree2.DropHintColor); Assert.AreEqual(tree.DefaultFormat.FontName, tree2.DefaultFormat.FontName); Assert.AreEqual(tree.DefaultFormat.Color, tree2.DefaultFormat.Color); Assert.AreEqual(tree.NoteForeColor, tree.NoteForeColor); }
public void DeserializeSerialize_RichNotesMap() { MindMapSerializer s = new MindMapSerializer(); string originalText = File.ReadAllText(@"Resources\RichNotesMap.mm"); MapTree tree = new MapTree(); s.Deserialize(originalText, tree); using (MemoryStream stream = new MemoryStream()) { s.Serialize(stream, tree); stream.Position = 0; string generatedText = new StreamReader(stream).ReadToEnd(); Assert.AreEqual(originalText, generatedText, "Serialized xml doesn't match this original."); } }
public void Serialize_WithImagePath() { MapTree tree = new MapTree(); var r = new MapNode(tree, "r"); r.Image = "MyImage.png"; r.ImageAlignment = ImageAlignment.AfterCenter; MindMapSerializer s = new MindMapSerializer(); using (MemoryStream stream = new MemoryStream()) { s.Serialize(stream, tree); stream.Position = 0; string serializedText = new StreamReader(stream).ReadToEnd(); var tree2 = new MapTree(); s.Deserialize(serializedText, tree2); Assert.AreEqual("MyImage.png", tree2.RootNode.Image); Assert.AreEqual(ImageAlignment.AfterCenter, tree2.RootNode.ImageAlignment); } }
public void Serialize_WithImageSize() { MapTree tree = new MapTree(); var r = new MapNode(tree, "r"); r.Image = "MyImage.png"; r.ImageSize = new System.Drawing.Size(10, 20); MindMapSerializer s = new MindMapSerializer(); using (MemoryStream stream = new MemoryStream()) { s.Serialize(stream, tree); stream.Position = 0; string serializedText = new StreamReader(stream).ReadToEnd(); var tree2 = new MapTree(); s.Deserialize(serializedText, tree2); Assert.AreEqual("MyImage.png", tree2.RootNode.Image); Assert.AreEqual(10, tree2.RootNode.ImageSize.Width); } }
/// <summary> /// Confirming that MapView look doesn't change by serializing and deserializing /// </summary> /// <param name="mapCtrl"></param> private void VerifySerializeDeserialize(MapCtrl mapCtrl) { //1. save MapView as image mapCtrl.MapView.SelectedNodes.Add(mapCtrl.MapView.Tree.RootNode, false); using (var refImage = mapCtrl.MapView.DrawToBitmap()) { //2. serialize var s = new MindMapSerializer(); MemoryStream stream = new MemoryStream(); s.Serialize(stream, mapCtrl.MapView.Tree); stream.Position = 0; string generatedText = new StreamReader(stream).ReadToEnd(); stream.Close(); //3. deserialize MapTree newTree = new MapTree(); s.Deserialize(generatedText, newTree); newTree.SelectedNodes.Add(newTree.RootNode, false); DialogManager dialogs = A.Fake <DialogManager>(); A.CallTo(dialogs).Where(call => call.Method.Name == "SeekDeleteConfirmation").WithReturnType <bool>().Returns(true); MapCtrl mapCtrl2 = new MapCtrl(new MapView(newTree), dialogs, null); //4. save new MapView image and compare using (var image = mapCtrl2.MapView.DrawToBitmap()) { if (SAVE_ACTUAL_IMAGE) { refImage.Save(@"Resources\MapCtrl_BeforeSerialization.png"); } if (SAVE_ACTUAL_IMAGE) { image.Save(@"Resources\MapCtrl_AfterDeseriallization.png"); } Assert.AreEqual(0.0f, refImage.PercentageDifference(image, 0), "MapCtrl Test: Final image doesn't match."); } } }
/// <summary> /// Confirming that MapView look doesn't change by serializing and deserializing /// </summary> /// <param name="mapCtrl"></param> private void VerifySerializeDeserialize(MapCtrl mapCtrl) { //1. save MapView as image mapCtrl.MapView.SelectedNodes.Add(mapCtrl.MapView.Tree.RootNode, false); using (var refImage = mapCtrl.MapView.DrawToBitmap()) { //2. serialize var s = new MindMapSerializer(); MemoryStream stream = new MemoryStream(); s.Serialize(stream, mapCtrl.MapView.Tree); stream.Position = 0; string generatedText = new StreamReader(stream).ReadToEnd(); stream.Close(); //3. deserialize MapTree newTree = new MapTree(); s.Deserialize(generatedText, newTree); newTree.SelectedNodes.Add(newTree.RootNode, false); MapCtrl mapCtrl2 = new MapCtrl(new MapView(newTree), new MainCtrlStub(new Form())); //4. save new MapView image and compare using (var image = mapCtrl2.MapView.DrawToBitmap()) { if (SAVE_ACTUAL_IMAGE) { refImage.Save(@"Resources\MapCtrl_BeforeSerialization.png"); } if (SAVE_ACTUAL_IMAGE) { image.Save(@"Resources\MapCtrl_AfterDeseriallization.png"); } Assert.AreEqual(0.0f, refImage.PercentageDifference(image, 0), "MapCtrl Test: Final image doesn't match."); } } }
/// <summary> /// Save Changes /// </summary> public void Save() { Debug.Assert(FileName != null, "Persistent Tree: File name is null."); var serializer = new MindMapSerializer(); using (var fileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write)) { serializer.Serialize(fileStream, Tree); } IsDirty = false; manager._InvokeTreeSaved(this); }