From dda0bd7d5e7f82afa7bb53bce41aa1791f2b86b8 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 25 Jul 2022 03:25:23 +1000 Subject: [PATCH] Construction graph node test (#9995) * Construction graph node test * fix the test Co-authored-by: wrexbe --- .../Construction/ConstructionPrototypeTest.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs b/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs index 2377b6abca..e9e3e64229 100644 --- a/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs +++ b/Content.IntegrationTests/Tests/Construction/ConstructionPrototypeTest.cs @@ -1,6 +1,10 @@ using System.Threading.Tasks; +using Content.Server.Construction.Components; using Content.Shared.Construction.Prototypes; using NUnit.Framework; +using Robust.Shared.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Maths; using Robust.Shared.Prototypes; namespace Content.IntegrationTests.Tests.Construction @@ -10,6 +14,42 @@ namespace Content.IntegrationTests.Tests.Construction { // discount linter for construction graphs // TODO: Create serialization validators for these? + // Top test definitely can be but writing a serializer takes ages. + + /// + /// Checks every entity prototype with a construction component has a valid start node. + /// + [Test] + public async Task TestStartNodeValid() + { + await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true}); + var server = pairTracker.Pair.Server; + + var entMan = server.ResolveDependency(); + var protoMan = server.ResolveDependency(); + + var map = await PoolManager.CreateTestMap(pairTracker); + + await server.WaitAssertion(() => + { + foreach (var proto in protoMan.EnumeratePrototypes()) + { + if (!proto.Components.ContainsKey("Construction")) + continue; + + var ent = entMan.SpawnEntity(proto.ID, new MapCoordinates(Vector2.Zero, map.MapId)); + var construction = entMan.GetComponent(ent); + + var graph = protoMan.Index(construction.Graph); + entMan.DeleteEntity(ent); + + Assert.That(graph.Nodes.ContainsKey(construction.Node), + $"Found no startNode \"{construction.Node}\" on graph \"{graph.ID}\" for entity \"{proto.ID}\"!"); + } + }); + + await pairTracker.CleanReturnAsync(); + } [Test] public async Task TestStartIsValid()