public void SerializesAndDeserializesCorrectly() { // I.e. deserialized(serialized(PROJECT)) should equal PROJECT string tmpPath = Path.GetTempPath(); MyConfiguration.SetupModuleSearchPath(); MyConfiguration.LoadModules(); MyConfiguration.KnownNodes.Add(typeof(TestNode), new MyNodeConfig()); var project = new MyProject(); project.Network = project.CreateNode <MyNetwork>(); project.Network.Name = "Network"; project.CreateWorld(typeof(MyTestingWorld)); project.Name = "test"; var node = project.CreateNode <TestNode>(); project.Network.AddChild(node); project.Restore(); string serialized = project.Serialize(tmpPath); MyProject deserializedProject = MyProject.Deserialize(serialized, tmpPath); // MaxDifferences = 20 - A magic number. It shows more than one difference in the log. // There should eventually be zero differences, so this number can be arbitrary. Adjust as needed. // Observers are ignored - there are none, and the (de)serialization mechanism works with them in a special way. var compareLogic = new CompareLogic(new ComparisonConfig { MaxDifferences = 20, MembersToIgnore = new List <string> { "Observers" } }); ComparisonResult result = compareLogic.Compare(project, deserializedProject); m_output.WriteLine(result.DifferencesString); Assert.True(result.AreEqual); }
private void CreateNewProject() { var oldProject = Project; Project = new MyProject(); Project.Network = Project.CreateNode<MyNetwork>(); Project.Network.Name = "Network"; string tmpPath = Path.GetTempFileName(); Project.Name = MyProject.MakeNameFromPath(tmpPath); worldList.SelectedIndex = -1; worldList.SelectedItem = MyConfiguration.KnownWorlds.Values.First(); Text = TITLE_TEXT + " - New Project"; exportStateButton.Enabled = false; clearDataButton.Enabled = false; Project.Restore(); RestoreDashboardForm(); UndoManager.Clear(); SaveState(GetSerializedProject(tmpPath), tmpPath, "New project"); RefreshUndoRedoButtons(); ApplyProjectOptions(); // Apply default project options such as save on stop to UI. saveFileDialog.FileName = string.Empty; }