From 72c763cd11d1c5bb24c8ca2e25fc5e86fabc1a8d Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 21 Feb 2021 22:20:11 +1100 Subject: [PATCH] Add storage fill test (#3352) Validates amounts (useful) and prototypes (less useful given SpawnEntityTest exists) Co-authored-by: Metal Gear Sloth --- .../Tests/StorageFillTest.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Content.IntegrationTests/Tests/StorageFillTest.cs diff --git a/Content.IntegrationTests/Tests/StorageFillTest.cs b/Content.IntegrationTests/Tests/StorageFillTest.cs new file mode 100644 index 0000000000..893bc5e7f3 --- /dev/null +++ b/Content.IntegrationTests/Tests/StorageFillTest.cs @@ -0,0 +1,42 @@ +#nullable enable +using System.Threading.Tasks; +using NUnit.Framework; +using Robust.Shared.Prototypes; +using Robust.Shared.Utility; +using YamlDotNet.RepresentationModel; + +namespace Content.IntegrationTests.Tests +{ + [TestFixture] + public sealed class StorageFillTest : ContentIntegrationTest + { + [Test] + public async Task TestStorageFillPrototypes() + { + var server = StartServerDummyTicker(); + await server.WaitIdleAsync(); + var protoManager = server.ResolveDependency(); + + await server.WaitAssertion(() => + { + foreach (var proto in protoManager.EnumeratePrototypes()) + { + if (!proto.Components.TryGetValue("StorageFill", out var storageNode) || + !storageNode.TryGetNode("contents", out YamlSequenceNode? contentsNode)) continue; + + foreach (var child in contentsNode) + { + if (child is not YamlMappingNode mapping) continue; + var name = mapping.GetNode("name").AsString(); + Assert.That(protoManager.HasIndex(name), $"Unable to find StorageFill prototype of {name} in prototype {proto.ID}"); + + if (mapping.TryGetNode("amount", out var amount)) + { + Assert.That(amount.AsInt() > 0, $"Specified invalid amount of {amount} for prototype {proto.ID}"); + } + } + } + }); + } + } +}