diff --git a/Assets/Editor/PresentationSnapshotContractTests.cs b/Assets/Editor/PresentationSnapshotContractTests.cs new file mode 100644 index 000000000..0617ef723 --- /dev/null +++ b/Assets/Editor/PresentationSnapshotContractTests.cs @@ -0,0 +1,69 @@ +using AibisDream.SaveSystem; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using NUnit.Framework; + +namespace AibisDream.SystemEditor.Tests +{ + public sealed class PresentationSnapshotContractTests + { + [Test] + public void Providers_UseDistinctStableIdsAndRestoreBeforeScreen() + { + var showcase = new ShowcaseSnapshotProvider(); + var playTool = new PlayToolSnapshotProvider(); + var screen = new ScreenSnapshotProvider(); + + Assert.That(showcase.SaveId, Is.EqualTo("showcase")); + Assert.That(playTool.SaveId, Is.EqualTo("playTool")); + Assert.That(showcase.RestoreOrder, Is.LessThan(playTool.RestoreOrder)); + Assert.That(playTool.RestoreOrder, Is.LessThan(screen.RestoreOrder)); + } + + [Test] + public void PresentationSections_RoundTripThroughSnapshotJson() + { + var source = new SaveSnapshot(); + source.sections[SnapshotProviderIds.PlayTool] = new PlayToolSnapshotDto + { + isObjVisible = true, + objPicName = "证物", + isFullScreenVisible = true, + fullScreenPicName = "教室" + }; + source.sections[SnapshotProviderIds.Showcase] = new ShowcaseSnapshotDto + { + displayMode = nameof(ShowcaseDisplayMode.Small), + picName = "D2S轱辘", + usesSplitLayers = true + }; + + var json = JsonConvert.SerializeObject(source); + var restored = JsonConvert.DeserializeObject(json); + var playTool = ((JObject)restored.sections[SnapshotProviderIds.PlayTool]) + .ToObject(); + var showcase = ((JObject)restored.sections[SnapshotProviderIds.Showcase]) + .ToObject(); + + Assert.That(playTool.isObjVisible, Is.True); + Assert.That(playTool.objPicName, Is.EqualTo("证物")); + Assert.That(playTool.isFullScreenVisible, Is.True); + Assert.That(playTool.fullScreenPicName, Is.EqualTo("教室")); + Assert.That(showcase.displayMode, Is.EqualTo(nameof(ShowcaseDisplayMode.Small))); + Assert.That(showcase.picName, Is.EqualTo("D2S轱辘")); + Assert.That(showcase.usesSplitLayers, Is.True); + Assert.That(restored.schemaVersion, Is.EqualTo(1)); + } + + [Test] + public void OldSnapshotWithoutPresentationSections_RemainsCompatible() + { + var restored = JsonConvert.DeserializeObject( + "{\"schemaVersion\":1,\"sections\":{}}"); + + Assert.That(restored.schemaVersion, Is.EqualTo(SaveSnapshotSchema.CurrentVersion)); + Assert.That(restored.sections.ContainsKey(SnapshotProviderIds.PlayTool), Is.False); + Assert.That(restored.sections.ContainsKey(SnapshotProviderIds.Showcase), Is.False); + } + } +} diff --git a/Assets/Editor/PresentationSnapshotContractTests.cs.meta b/Assets/Editor/PresentationSnapshotContractTests.cs.meta new file mode 100644 index 000000000..137f965da --- /dev/null +++ b/Assets/Editor/PresentationSnapshotContractTests.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: aa21851c46624f77a67e29c86ec854c9