Add unit test asserting that saving, loading & saving the map produces identical output. (#348)

Also fixed PowerProvider violating this.
This commit is contained in:
Pieter-Jan Briers
2019-09-19 13:46:01 +02:00
committed by GitHub
parent 6c97b63e59
commit 35e88ea62c
3 changed files with 64 additions and 2 deletions

View File

@@ -0,0 +1,54 @@
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using Robust.Server.Interfaces.Maps;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Resources;
using Robust.Shared.Map;
using Robust.Shared.Utility;
namespace Content.IntegrationTests
{
/// <summary>
/// Tests that the
/// </summary>
[TestFixture]
public class SaveLoadSaveTest : ContentIntegrationTest
{
[Test]
public async Task SaveLoadSave()
{
var server = StartServer();
await server.WaitIdleAsync();
var mapLoader = server.ResolveDependency<IMapLoader>();
var mapManager = server.ResolveDependency<IMapManager>();
server.Post(() =>
{
mapLoader.SaveBlueprint(new GridId(2), "save load save 1.yml");
var map = mapManager.CreateMap();
var grid = mapLoader.LoadBlueprint(map, "save load save 1.yml");
mapLoader.SaveBlueprint(grid.Index, "save load save 2.yml");
});
await server.WaitIdleAsync();
var userData = server.ResolveDependency<IResourceManager>().UserData;
string one;
string two;
using (var stream = userData.Open(new ResourcePath("save load save 1.yml"), FileMode.Open))
using (var reader = new StreamReader(stream))
{
one = reader.ReadToEnd();
}
using (var stream = userData.Open(new ResourcePath("save load save 2.yml"), FileMode.Open))
using (var reader = new StreamReader(stream))
{
two = reader.ReadToEnd();
}
Assert.That(one, Is.EqualTo(two));
}
}
}

View File

@@ -32,6 +32,8 @@ namespace Content.Server.GameObjects.Components.Power
} }
} }
protected virtual bool SaveLoad => true;
/// <summary> /// <summary>
/// The method of draw we will try to use to place our load set via component parameter, defaults to using power providers /// The method of draw we will try to use to place our load set via component parameter, defaults to using power providers
/// </summary> /// </summary>
@@ -191,8 +193,12 @@ namespace Content.Server.GameObjects.Components.Power
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref _drawType, "drawtype", DrawTypes.Provider); serializer.DataField(ref _drawType, "drawtype", DrawTypes.Provider);
serializer.DataField(ref _load, "load", 100);
serializer.DataField(ref _priority, "priority", Powernet.Priority.Medium); serializer.DataField(ref _priority, "priority", Powernet.Priority.Medium);
if (SaveLoad)
{
serializer.DataField(ref _load, "load", 100);
}
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message)

View File

@@ -23,6 +23,8 @@ namespace Content.Server.GameObjects.Components.Power
/// <inheritdoc /> /// <inheritdoc />
public override DrawTypes DrawType { get; protected set; } = DrawTypes.Node; public override DrawTypes DrawType { get; protected set; } = DrawTypes.Node;
protected override bool SaveLoad => false;
/// <summary> /// <summary>
/// Variable that determines the range that the power provider will try to supply power to /// Variable that determines the range that the power provider will try to supply power to
/// </summary> /// </summary>