Example #1
0
    public void CartNameInHeader()
    {
        // use the sample data to fake a project
        var srcProject    = sampleData.Create() as Project;
        var expectedTitle = SnesSampleRomDataFactory.GetSampleUtf8CartridgeTitle();

        TestRomCartTitle(srcProject, expectedTitle);
    }
    public void FullSerializeAndDeserialize()
    {
        var srcProject = sampleProjectCreator.Create() as Project;

        var expectedTitle = SnesSampleRomDataFactory.GetSampleUtf8CartridgeTitle();

        srcProject.Data.Comments.Count.Should().BeGreaterThan(0);
        srcProject.Data.Labels.Labels.Count().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.GetFileBytes().ToList();

        // save it to create an output byte stream, we'd normally write this to the disk

        var outputBytes = serializer.Save(srcProject);

        // now do the reverse and load our output back as the input
        var projectOpenInfo  = serializer.Load(outputBytes);
        var deserializedRoot = projectOpenInfo.Root;
        var warning          = projectOpenInfo.OpenResult.Warning;

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

        // now we can do a full compare between the original project, and the project which has been cycled through
        // serialization and deserialization
        warning.Should().Be(null);
        deserializedRoot.Project.Data.Labels.Labels.Count().Should().Be(srcProject.Data.Labels.Labels.Count());

        void TestEquivalent(Func <Project, object> func, ProjectXmlSerializer.Root root, Project project) =>
        func(root.Project).Should().BeEquivalentTo(func(project));

        TestEquivalent(x => x.Data.RomBytes, deserializedRoot, srcProject);
        TestEquivalent(x => x.Data.Comments, deserializedRoot, srcProject);
        TestEquivalent(x => x.Data.Labels, deserializedRoot, srcProject);

        deserializedRoot.Project.Should().BeEquivalentTo(srcProject);

        deserializedRoot.Project.Data.Comments.Count.Should().BePositive();
        deserializedRoot.Project.Data.Labels.Labels.Count().Should().BePositive();

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