70 lines
2.9 KiB
C#
70 lines
2.9 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|