Files

69 lines
2.6 KiB
C#
Raw Permalink Normal View History

2023-01-07 13:09:05 -05:00
#nullable enable
using Content.Server.Stack;
using Content.Shared.Stacks;
using Content.Shared.Materials;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.Materials
{
/// <summary>
/// Materials and stacks have some odd relationships to entities,
/// so we need some test coverage for them.
/// </summary>
2023-01-07 13:09:05 -05:00
[TestFixture]
[TestOf(typeof(StackSystem))]
[TestOf(typeof(MaterialPrototype))]
public sealed class MaterialPrototypeSpawnsStackMaterialTest
{
[Test]
public async Task MaterialPrototypeSpawnsStackMaterial()
{
2023-08-25 02:56:51 +02:00
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
2023-01-07 13:09:05 -05:00
await server.WaitIdleAsync();
var mapManager = server.ResolveDependency<IMapManager>();
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var testMap = await pair.CreateTestMap();
2023-01-07 13:09:05 -05:00
await server.WaitAssertion(() =>
{
var allMaterialProtos = prototypeManager.EnumeratePrototypes<MaterialPrototype>();
var coords = testMap.GridCoords;
2023-01-08 11:36:32 +13:00
Assert.Multiple(() =>
2023-01-07 13:09:05 -05:00
{
2023-01-08 11:36:32 +13:00
foreach (var proto in allMaterialProtos)
{
2023-06-14 20:49:23 -04:00
if (proto.StackEntity == null)
2023-01-08 11:36:32 +13:00
continue;
2023-01-07 13:09:05 -05:00
2023-01-08 11:36:32 +13:00
var spawned = entityManager.SpawnEntity(proto.StackEntity, coords);
2023-01-07 13:09:05 -05:00
2023-01-08 11:36:32 +13:00
Assert.That(entityManager.TryGetComponent<StackComponent>(spawned, out var stack),
$"{proto.ID} 'stack entity' {proto.StackEntity} does not have the stack component");
2023-01-07 13:09:05 -05:00
2023-01-08 11:36:32 +13:00
Assert.That(entityManager.HasComponent<MaterialComponent>(spawned),
$"{proto.ID} 'material stack' {proto.StackEntity} does not have the material component");
2023-01-07 13:09:05 -05:00
2023-01-08 11:36:32 +13:00
StackPrototype? stackProto = null;
Assert.That(stack?.StackTypeId != null && prototypeManager.TryIndex(stack.StackTypeId, out stackProto),
$"{proto.ID} material has no stack prototype");
if (stackProto != null)
Assert.That(proto.StackEntity, Is.EqualTo(stackProto.Spawn));
}
});
2023-01-07 13:09:05 -05:00
mapManager.DeleteMap(testMap.MapId);
});
2023-03-11 14:01:44 +11:00
2023-08-25 02:56:51 +02:00
await pair.CleanReturnAsync();
2023-01-07 13:09:05 -05:00
}
}
}