test(save): 添加演出快照契约测试

校验 showcase/playTool/screen 的 SaveId 与还原顺序,
以及快照 section 的 JSON 序列化往返。
This commit is contained in:
2026-07-19 00:00:01 +08:00
parent a5e417eeae
commit 081ed0d883
2 changed files with 71 additions and 0 deletions
@@ -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<SaveSnapshot>(json);
var playTool = ((JObject)restored.sections[SnapshotProviderIds.PlayTool])
.ToObject<PlayToolSnapshotDto>();
var showcase = ((JObject)restored.sections[SnapshotProviderIds.Showcase])
.ToObject<ShowcaseSnapshotDto>();
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<SaveSnapshot>(
"{\"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);
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: aa21851c46624f77a67e29c86ec854c9