ResearchTest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Content.Shared.Lathe;
  4. using Content.Shared.Research.Prototypes;
  5. using Robust.Shared.GameObjects;
  6. using Robust.Shared.Prototypes;
  7. namespace Content.IntegrationTests.Tests;
  8. [TestFixture]
  9. public sealed class ResearchTest
  10. {
  11. [Test]
  12. public async Task DisciplineValidTierPrerequesitesTest()
  13. {
  14. await using var pair = await PoolManager.GetServerClient();
  15. var server = pair.Server;
  16. var protoManager = server.ResolveDependency<IPrototypeManager>();
  17. await server.WaitAssertion(() =>
  18. {
  19. var allTechs = protoManager.EnumeratePrototypes<TechnologyPrototype>().ToList();
  20. Assert.Multiple(() =>
  21. {
  22. foreach (var discipline in protoManager.EnumeratePrototypes<TechDisciplinePrototype>())
  23. {
  24. foreach (var tech in allTechs)
  25. {
  26. if (tech.Discipline != discipline.ID)
  27. continue;
  28. // we ignore these, anyways
  29. if (tech.Tier == 1)
  30. continue;
  31. Assert.That(tech.Tier, Is.GreaterThan(0), $"Technology {tech} has invalid tier {tech.Tier}.");
  32. Assert.That(discipline.TierPrerequisites.ContainsKey(tech.Tier),
  33. $"Discipline {discipline.ID} does not have a TierPrerequisites definition for tier {tech.Tier}");
  34. }
  35. }
  36. });
  37. });
  38. await pair.CleanReturnAsync();
  39. }
  40. [Test]
  41. public async Task AllTechPrintableTest()
  42. {
  43. await using var pair = await PoolManager.GetServerClient();
  44. var server = pair.Server;
  45. var entMan = server.ResolveDependency<IEntityManager>();
  46. var protoManager = server.ResolveDependency<IPrototypeManager>();
  47. var compFact = server.ResolveDependency<IComponentFactory>();
  48. var latheSys = entMan.System<SharedLatheSystem>();
  49. await server.WaitAssertion(() =>
  50. {
  51. var allEnts = protoManager.EnumeratePrototypes<EntityPrototype>();
  52. var latheTechs = new HashSet<ProtoId<LatheRecipePrototype>>();
  53. foreach (var proto in allEnts)
  54. {
  55. if (proto.Abstract)
  56. continue;
  57. if (pair.IsTestPrototype(proto))
  58. continue;
  59. if (!proto.TryGetComponent<LatheComponent>(out var lathe, compFact))
  60. continue;
  61. latheSys.AddRecipesFromPacks(latheTechs, lathe.DynamicPacks);
  62. if (proto.TryGetComponent<EmagLatheRecipesComponent>(out var emag, compFact))
  63. latheSys.AddRecipesFromPacks(latheTechs, emag.EmagDynamicPacks);
  64. }
  65. Assert.Multiple(() =>
  66. {
  67. // check that every recipe a tech adds can be made on some lathe
  68. var unlockedTechs = new HashSet<ProtoId<LatheRecipePrototype>>();
  69. foreach (var tech in protoManager.EnumeratePrototypes<TechnologyPrototype>())
  70. {
  71. unlockedTechs.UnionWith(tech.RecipeUnlocks);
  72. foreach (var recipe in tech.RecipeUnlocks)
  73. {
  74. Assert.That(latheTechs, Does.Contain(recipe), $"Recipe '{recipe}' from tech '{tech.ID}' cannot be unlocked on any lathes.");
  75. }
  76. }
  77. // now check that every dynamic recipe a lathe lists can be unlocked
  78. foreach (var recipe in latheTechs)
  79. {
  80. Assert.That(unlockedTechs, Does.Contain(recipe), $"Recipe '{recipe}' is dynamic on a lathe but cannot be unlocked by research.");
  81. }
  82. });
  83. });
  84. await pair.CleanReturnAsync();
  85. }
  86. }