mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
* prototype composition * oops * better * fixes build * should fix * misc fixes & circle test * moar circle checks * adds tests Co-authored-by: Paul <ritter.paul1@gmail.com>
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.Serialization.Markdown.Mapping;
|
|
using TerraFX.Interop.Windows;
|
|
|
|
namespace Robust.UnitTesting.Shared.Serialization;
|
|
|
|
[TestFixture]
|
|
public sealed class CompositionTest : SerializationTest
|
|
{
|
|
[DataDefinition]
|
|
private sealed class CompositionTestClass
|
|
{
|
|
[DataField("f1")] public int ChildValue;
|
|
[DataField("f2")] public int Parent1Value;
|
|
[DataField("f3")] public int Parent2Value;
|
|
[DataField("f4"), NeverPushInheritance]
|
|
public int NeverPushValueParent1;
|
|
[DataField("f5"), NeverPushInheritance]
|
|
public int NeverPushValueParent2;
|
|
}
|
|
|
|
[Test]
|
|
public void TestPushComposition()
|
|
{
|
|
var child = new MappingDataNode { { "f1", "1" } };
|
|
var parent1 = new MappingDataNode
|
|
{
|
|
{ "f1", "2" },
|
|
{ "f2", "1" },
|
|
{ "f4", "1" }
|
|
};
|
|
var parent2 = new MappingDataNode
|
|
{
|
|
{ "f1", "3" },
|
|
{ "f2", "2" },
|
|
{ "f3", "1" },
|
|
{ "f5", "1" }
|
|
};
|
|
|
|
var finalMapping = Serialization.PushComposition<CompositionTestClass, MappingDataNode>(new[] { parent1, parent2 }, child);
|
|
var val = Serialization.Read<CompositionTestClass>(finalMapping);
|
|
|
|
Assert.That(val.ChildValue, Is.EqualTo(1));
|
|
Assert.That(val.Parent1Value, Is.EqualTo(1));
|
|
Assert.That(val.Parent2Value, Is.EqualTo(1));
|
|
Assert.That(val.NeverPushValueParent1, Is.EqualTo(0));
|
|
Assert.That(val.NeverPushValueParent2, Is.EqualTo(0));
|
|
}
|
|
}
|