73 lines
3.2 KiB
C#
73 lines
3.2 KiB
C#
using AibisDream.SaveSystem;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using NUnit.Framework;
|
|
|
|
namespace AibisDream.SystemEditor.Tests
|
|
{
|
|
public sealed class SaveSnapshotContractTests
|
|
{
|
|
[Test]
|
|
public void PresentationProviders_KeepStableIdsAndRestoreOrder()
|
|
{
|
|
var showcase = new ShowcaseSnapshotProvider();
|
|
var day2Sleep = new Day2SleepPresentationSnapshotProvider();
|
|
var playTool = new PlayToolSnapshotProvider();
|
|
var screen = new ScreenSnapshotProvider();
|
|
|
|
Assert.That(showcase.SaveId, Is.EqualTo("showcase"));
|
|
Assert.That(day2Sleep.SaveId, Is.EqualTo("day2SleepPresentation"));
|
|
Assert.That(playTool.SaveId, Is.EqualTo("playTool"));
|
|
Assert.That(showcase.RestoreOrder, Is.LessThan(day2Sleep.RestoreOrder));
|
|
Assert.That(day2Sleep.RestoreOrder, Is.LessThan(playTool.RestoreOrder));
|
|
Assert.That(playTool.RestoreOrder, Is.LessThan(screen.RestoreOrder));
|
|
}
|
|
|
|
[Test]
|
|
public void PresentationSections_RoundTripAndLegacySnapshotsRemainReadable()
|
|
{
|
|
var source = new SaveSnapshot();
|
|
source.sections[SnapshotProviderIds.Showcase] = new ShowcaseSnapshotDto
|
|
{
|
|
displayMode = ShowcaseDisplayMode.Large.ToString(),
|
|
picName = "D2S星图",
|
|
isBackgroundVisible = true
|
|
};
|
|
source.sections[SnapshotProviderIds.PlayTool] = new PlayToolSnapshotDto
|
|
{
|
|
isObjVisible = true,
|
|
objPicName = "证物",
|
|
objIsLocalized = true,
|
|
isFullScreenVisible = true,
|
|
fullScreenPicName = "病历",
|
|
fullScreenIsLocalized = true
|
|
};
|
|
|
|
var restored = JsonConvert.DeserializeObject<SaveSnapshot>(
|
|
JsonConvert.SerializeObject(source));
|
|
var showcase = ((JObject)restored.sections[SnapshotProviderIds.Showcase])
|
|
.ToObject<ShowcaseSnapshotDto>();
|
|
var playTool = ((JObject)restored.sections[SnapshotProviderIds.PlayTool])
|
|
.ToObject<PlayToolSnapshotDto>();
|
|
|
|
Assert.That(restored.schemaVersion, Is.EqualTo(SaveSnapshotSchema.CurrentVersion));
|
|
Assert.That(showcase.displayMode, Is.EqualTo("Large"));
|
|
Assert.That(showcase.picName, Is.EqualTo("D2S星图"));
|
|
Assert.That(playTool.objPicName, Is.EqualTo("证物"));
|
|
Assert.That(playTool.objIsLocalized, Is.True);
|
|
Assert.That(playTool.fullScreenPicName, Is.EqualTo("病历"));
|
|
Assert.That(playTool.fullScreenIsLocalized, Is.True);
|
|
|
|
var legacyPlayTool = JsonConvert.DeserializeObject<PlayToolSnapshotDto>(
|
|
"{\"isObjVisible\":true,\"objPicName\":\"legacy\"}");
|
|
Assert.That(legacyPlayTool.objIsLocalized, Is.False);
|
|
Assert.That(legacyPlayTool.fullScreenIsLocalized, Is.False);
|
|
|
|
var legacy = JsonConvert.DeserializeObject<SaveSnapshot>(
|
|
"{\"schemaVersion\":1,\"sections\":{}}");
|
|
Assert.That(legacy.schemaVersion, Is.EqualTo(1));
|
|
Assert.That(legacy.sections, Is.Empty);
|
|
}
|
|
}
|
|
}
|