Files
RobustToolbox/Robust.Shared.IntegrationTests/Serialization/SerializationPriorityTest.cs
PJB3005 788e9386fd Split up test project
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
2025-12-16 01:36:53 +01:00

76 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.Markdown;
using Robust.Shared.Serialization.Markdown.Mapping;
using Robust.Shared.Serialization.Markdown.Sequence;
using YamlDotNet.RepresentationModel;
namespace Robust.UnitTesting.Shared.Serialization
{
internal sealed class SerializationPriorityTest : OurRobustUnitTest
{
[Test]
public void Test()
{
var serializationManager = IoCManager.Resolve<ISerializationManager>();
serializationManager.Initialize();
var prototype = @"
- type: PriorityTest
first: A
second: B
third: C";
var yamlStream = new YamlStream();
yamlStream.Load(new StringReader(prototype));
var mapping = yamlStream.Documents[0].RootNode.ToDataNodeCast<SequenceDataNode>().Cast<MappingDataNode>(0);
var component = serializationManager.Read<PriorityTestComponent>(mapping, notNullableOverride: true);
Assert.That(component.Strings.Count, Is.EqualTo(3));
Assert.That(component.First, Is.EqualTo("A"));
Assert.That(component.Second, Is.EqualTo("C"));
Assert.That(component.Third, Is.EqualTo("B"));
}
}
internal sealed partial class PriorityTestComponent : Component, ISerializationHooks
{
public readonly List<string> Strings = new() {string.Empty, string.Empty, string.Empty};
[DataField("first", priority: 3)]
public string First
{
get => Strings[0];
set => Strings.Add(value);
}
[DataField("second", priority: 1)]
public string Second
{
get => Strings[1];
set => Strings.Add(value);
}
[DataField("third", priority: 2)]
public string Third
{
get => Strings[2];
set => Strings.Add(value);
}
void ISerializationHooks.AfterDeserialization()
{
Strings.RemoveRange(0, 3);
}
}
}