1
0

MaterialTests.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #nullable enable
  2. using Content.Server.Stack;
  3. using Content.Shared.Stacks;
  4. using Content.Shared.Materials;
  5. using Robust.Shared.GameObjects;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.IntegrationTests.Tests.Materials
  8. {
  9. /// <summary>
  10. /// Materials and stacks have some odd relationships to entities,
  11. /// so we need some test coverage for them.
  12. /// </summary>
  13. [TestFixture]
  14. [TestOf(typeof(StackSystem))]
  15. [TestOf(typeof(MaterialPrototype))]
  16. public sealed class MaterialPrototypeSpawnsStackMaterialTest
  17. {
  18. [Test]
  19. public async Task MaterialPrototypeSpawnsStackMaterial()
  20. {
  21. await using var pair = await PoolManager.GetServerClient();
  22. var server = pair.Server;
  23. await server.WaitIdleAsync();
  24. var mapSystem = server.System<SharedMapSystem>();
  25. var prototypeManager = server.ResolveDependency<IPrototypeManager>();
  26. var entityManager = server.ResolveDependency<IEntityManager>();
  27. var testMap = await pair.CreateTestMap();
  28. await server.WaitAssertion(() =>
  29. {
  30. var allMaterialProtos = prototypeManager.EnumeratePrototypes<MaterialPrototype>();
  31. var coords = testMap.GridCoords;
  32. Assert.Multiple(() =>
  33. {
  34. foreach (var proto in allMaterialProtos)
  35. {
  36. if (proto.StackEntity == null)
  37. continue;
  38. var spawned = entityManager.SpawnEntity(proto.StackEntity, coords);
  39. Assert.That(entityManager.TryGetComponent<StackComponent>(spawned, out var stack),
  40. $"{proto.ID} 'stack entity' {proto.StackEntity} does not have the stack component");
  41. Assert.That(entityManager.HasComponent<MaterialComponent>(spawned),
  42. $"{proto.ID} 'material stack' {proto.StackEntity} does not have the material component");
  43. StackPrototype? stackProto = null;
  44. Assert.That(stack?.StackTypeId != null && prototypeManager.TryIndex(stack.StackTypeId, out stackProto),
  45. $"{proto.ID} material has no stack prototype");
  46. if (stackProto != null)
  47. Assert.That(proto.StackEntity, Is.EqualTo(stackProto.Spawn));
  48. }
  49. });
  50. mapSystem.DeleteMap(testMap.MapId);
  51. });
  52. await pair.CleanReturnAsync();
  53. }
  54. }
  55. }