Esempio n. 1
0
        private void FullSerializeAndDeserialize()
        {
            // use the sample data to fake a project
            var sampleProject = new Project {
                Data = SampleRomData.SampleData
            };

            // extract the bytes that would normally be in the SMC file (they only exist in code for this sample data)
            var romFileBytes = sampleProject.Data.GetFileBytes();

            // save it to create an output byte stream, we'd normally write this to the disk
            var serializer  = new ProjectXmlSerializer();
            var outputBytes = serializer.Save(sampleProject);

            // now do the reverse and load our output back as the input
            var(deserializedProject, warning) = serializer.Load(outputBytes);

            // final step, the loading process doesn't save the actual SMC file bytes, so we do it ourselves here
            deserializedProject.Data.CopyRomDataIn(romFileBytes);

            // now we can do a full compare between the original project, and the project which has been cycled through
            // serialization and deserialization
            Assert.True(warning == "");
            Assert.True(sampleProject.Equals(deserializedProject));
        }
        private void FullSerializeAndDeserialize()
        {
            // use the sample data to fake a project
            var srcProject = BuildSampleProject2();

            var expectedTitle = SampleRomData.GetSampleUtf8CartridgeTitle();

            srcProject.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Comment>().Should().BeGreaterThan(0);
            srcProject.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Label>().Should().BeGreaterThan(0);

            // extract the bytes that would normally be in the SMC file (they only exist in code for this sample data)
            var romFileBytes = srcProject.Data.RomByteSource.Bytes.Select(e => e?.Byte ?? 0).ToList().ToList();

            // save it to create an output byte stream, we'd normally write this to the disk
            var serializer  = new ProjectXmlSerializer();
            var outputBytes = serializer.Save(srcProject);

            // now do the reverse and load our output back as the input
            var(deserializedProject, warning) = serializer.Load(outputBytes);

            // final step, the loading process doesn't save the actual SMC file bytes, so we do it ourselves here
            deserializedProject.Project.Data.RomByteSource.SetBytesFrom(romFileBytes);

            // now we can do a full compare between the original project, and the project which has been cycled through
            // serialization and deserialization
            Assert.True(warning == "");
            Assert.True(srcProject.Equals(deserializedProject.Project));

            deserializedProject.Project.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Comment>().Should().BeGreaterThan(0);
            deserializedProject.Project.Data.SnesAddressSpace.GetAnnotationCountInAllChildren <Label>().Should().BeGreaterThan(0);

            CartNameTests.TestRomCartTitle(deserializedProject.Project, expectedTitle);
        }