mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Move to Central Package Management. Allows us to store NuGet package versions all in one place. Yay! * Update NuGet packages and fix code for changes. Notable: Changes to ILVerify. Npgsql doesn't need hacks for inet anymore, now we need hacks to make the old code work with this new reality. NUnit's analyzers are already complaining and I didn't even update it to 4.x yet. TerraFX changed to GetLastSystemError so error handling had to be changed. Buncha APIs have more NRT annotations. * Remove dotnet-eng NuGet package source. I genuinely don't know what this was for, and Central Package Management starts throwing warnings about it, so YEET. * Fix double loading of assemblies due to ALC shenanigans. Due to how the "sideloading" code for the ModLoader was set up, it would first try to load Microsoft.Extensions.Primitives from next to the content dll. But we already have that library in Robust! Chaos ensues. We now try to forcibly prioritize loading from the default ALC first to avoid this. * Remove Robust.Physics project. Never used. * Remove erroneous NVorbis reference. Should be VorbisPizza and otherwise wasn't used. * Sandbox fixes * Remove unused unit test package references. Castle.Core and NUnit.ConsoleRunner. * Update NUnit to 4.0.1 This requires replacing all the old assertion methods because they removed them 🥲 * Mute CA1416 (platform check) errors TerraFX started annotating APIs with this and I can't be arsed to entertain this analyzer so out it goes. * Fine ya cranky, no more CPM for Robust.Client.Injectors * Changelog * Oh so that's what dotnet-eng was used for. Yeah ok that makes sense. * Central package management for remaining 2 robust projects * Ok that was a bad idea let's just use NUnit 3 on the analyzer test project * Oh right forgot to remove this one * Update to a newer version of RemoteExecutor * Disable RemoteExecutor test https://github.com/dotnet/arcade/issues/8483 Yeah this package is not well maintained and clearly we can't rely on it. * Fix immutable list serialization
122 lines
5.2 KiB
C#
122 lines
5.2 KiB
C#
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.Serialization.Markdown.Mapping;
|
|
using Robust.Shared.Serialization.Markdown.Sequence;
|
|
|
|
namespace Robust.UnitTesting.Shared.Serialization;
|
|
|
|
/// <summary>
|
|
/// Tests that arrays and lists of virtual/abstract objects can be properly serialized and deserialized.
|
|
/// </summary>
|
|
public sealed partial class VirtualObjectArrayTest : SerializationTest
|
|
{
|
|
[ImplicitDataDefinitionForInheritors]
|
|
private abstract partial class BaseTestDataDef { }
|
|
|
|
private sealed partial class SealedTestDataDef : BaseTestDataDef { }
|
|
|
|
[Virtual]
|
|
private partial class VirtualTestDataDef : BaseTestDataDef { }
|
|
|
|
private sealed partial class ChildTestDef : VirtualTestDataDef { }
|
|
|
|
[Test]
|
|
public void SerializeVirtualObjectArrayTest()
|
|
{
|
|
var sequence = new SequenceDataNode
|
|
{
|
|
new MappingDataNode {Tag = $"!type:SealedTestDataDef"},
|
|
new MappingDataNode {Tag = $"!type:VirtualTestDataDef"},
|
|
new MappingDataNode {Tag = $"!type:ChildTestDef"}
|
|
};
|
|
|
|
{
|
|
// Deserialize the above yaml
|
|
var arr = Serialization.Read<BaseTestDataDef[]>(sequence, notNullableOverride: true);
|
|
|
|
// Ensure that the !type: tags were properly parsed
|
|
Assert.That(arr[0], Is.TypeOf(typeof(SealedTestDataDef)));
|
|
Assert.That(arr[1], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(arr[2], Is.TypeOf(typeof(ChildTestDef)));
|
|
|
|
// Write the parsed object back to yaml
|
|
var newSquence = Serialization.WriteValue(arr, notNullableOverride: true);
|
|
|
|
// Check that the yaml doesn't differ in any way.
|
|
var diff = newSquence.Except(sequence);
|
|
Assert.That(diff, Is.Null);
|
|
|
|
// And finally, double check that the serialized data can be re-deserialized (dataNode.Except isn't perfect).
|
|
arr = Serialization.Read<BaseTestDataDef[]>(newSquence, notNullableOverride: true);
|
|
Assert.That(arr[0], Is.TypeOf(typeof(SealedTestDataDef)));
|
|
Assert.That(arr[1], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(arr[2], Is.TypeOf(typeof(ChildTestDef)));
|
|
}
|
|
|
|
|
|
// Repeat the above, but using lists instead of arrays
|
|
{
|
|
var list = Serialization.Read<List<BaseTestDataDef>>(sequence, notNullableOverride: true);
|
|
Assert.That(list[0], Is.TypeOf(typeof(SealedTestDataDef)));
|
|
Assert.That(list[1], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(list[2], Is.TypeOf(typeof(ChildTestDef)));
|
|
|
|
var newSquence = Serialization.WriteValue(list, notNullableOverride: true);
|
|
var diff = newSquence.Except(sequence);
|
|
Assert.That(diff, Is.Null);
|
|
|
|
list = Serialization.Read<List<BaseTestDataDef>>(sequence, notNullableOverride: true);
|
|
Assert.That(list[0], Is.TypeOf(typeof(SealedTestDataDef)));
|
|
Assert.That(list[1], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(list[2], Is.TypeOf(typeof(ChildTestDef)));
|
|
}
|
|
|
|
// remove the first entry -- leave only entries that inherit from VirtualTestDataDef
|
|
sequence.RemoveAt(0);
|
|
|
|
// When writing, this will skip the !type tag for the first entry
|
|
var expectedSequence = new SequenceDataNode
|
|
{
|
|
new MappingDataNode(),
|
|
new MappingDataNode {Tag = $"!type:ChildTestDef"}
|
|
};
|
|
|
|
{
|
|
var virtArr = Serialization.Read<VirtualTestDataDef[]>(sequence, notNullableOverride: true);
|
|
Assert.That(virtArr[0], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(virtArr[1], Is.TypeOf(typeof(ChildTestDef)));
|
|
|
|
// The old sequence will now differ as it should not write the redundant !type tag
|
|
var newSquence = Serialization.WriteValue(virtArr, notNullableOverride: true);
|
|
var diff = newSquence.Except(sequence);
|
|
Assert.That(diff, Is.Not.Null);
|
|
|
|
diff = newSquence.Except(expectedSequence);
|
|
Assert.That(diff, Is.Null);
|
|
|
|
virtArr = Serialization.Read<VirtualTestDataDef[]>(newSquence, notNullableOverride: true);
|
|
Assert.That(virtArr[0], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(virtArr[1], Is.TypeOf(typeof(ChildTestDef)));
|
|
}
|
|
|
|
// And again, repeat for lists instead of arrays
|
|
{
|
|
var virtList = Serialization.Read<List<VirtualTestDataDef>>(sequence, notNullableOverride: true);
|
|
Assert.That(virtList[0], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(virtList[1], Is.TypeOf(typeof(ChildTestDef)));
|
|
|
|
var newSquence = Serialization.WriteValue(virtList, notNullableOverride: true);
|
|
var diff = newSquence.Except(sequence);
|
|
Assert.That(diff, Is.Not.Null);
|
|
|
|
diff = newSquence.Except(expectedSequence);
|
|
Assert.That(diff, Is.Null);
|
|
|
|
virtList = Serialization.Read<List<VirtualTestDataDef>>(newSquence, notNullableOverride: true);
|
|
Assert.That(virtList[0], Is.TypeOf(typeof(VirtualTestDataDef)));
|
|
Assert.That(virtList[1], Is.TypeOf(typeof(ChildTestDef)));
|
|
}
|
|
}
|
|
}
|