Пример #1
0
        private string GetSerializedProject(string fileName)
        {
            Project.Observers = new List <MyAbstractObserver>();  // potential sideffect
            ObserverViews.ForEach(ov => { ov.StoreWindowInfo(); Project.Observers.Add(ov.Observer); });

            Project.Name = Path.GetFileNameWithoutExtension(fileName);  // a little sideeffect (should be harmless)

            string serializedProject = Project.Serialize(Path.GetDirectoryName(fileName));

            Project.Observers = null;

            return(serializedProject);
        }
Пример #2
0
        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);
        }