From 66dc8f5df59c5a041a35bf641978c4714d7fb077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Guardia=20Fern=C3=A1ndez?= Date: Sat, 16 Oct 2021 16:06:01 +0200 Subject: [PATCH] Add test for deserializing nullable reagent units (#4899) --- .../Chemistry/ReagentUnitSerializationTest.cs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs diff --git a/Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs b/Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs new file mode 100644 index 0000000000..3aac172d5d --- /dev/null +++ b/Content.IntegrationTests/Tests/Chemistry/ReagentUnitSerializationTest.cs @@ -0,0 +1,43 @@ +using System.Reflection; +using Content.Shared.Chemistry.Reagent; +using NUnit.Framework; +using Robust.Shared.Serialization.Manager; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.Markdown.Mapping; +using Robust.Shared.Serialization.Markdown.Value; +using Robust.UnitTesting.Shared.Serialization; + +namespace Content.IntegrationTests.Tests.Chemistry +{ + public class ReagentUnitSerializationTest : SerializationTest + { + protected override Assembly[] Assemblies => new[] + { + typeof(ReagentUnitSerializationTest).Assembly + }; + + [Test] + public void DeserializeNullTest() + { + var node = new ValueDataNode("null"); + var unit = Serialization.ReadValue(node); + + Assert.That(unit, Is.Null); + } + + [Test] + public void DeserializeNullDefinitionTest() + { + var node = new MappingDataNode().Add("unit", "null"); + var definition = Serialization.ReadValueOrThrow(node); + + Assert.That(definition.Unit, Is.Null); + } + } + + [DataDefinition] + public class ReagentUnitTestDefinition + { + [DataField("unit")] public ReagentUnit? Unit { get; set; } = ReagentUnit.New(5); + } +}