RoleTests.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Linq;
  2. using Content.Server.Roles;
  3. using Content.Shared.Roles;
  4. using Content.Shared.Roles.Jobs;
  5. using Robust.Shared.GameObjects;
  6. using Robust.Shared.Reflection;
  7. namespace Content.IntegrationTests.Tests.Minds;
  8. [TestFixture]
  9. public sealed class RoleTests
  10. {
  11. /// <summary>
  12. /// Check that any prototype with a <see cref="MindRoleComponent"/> is properly configured
  13. /// </summary>
  14. [Test]
  15. public async Task ValidateRolePrototypes()
  16. {
  17. await using var pair = await PoolManager.GetServerClient();
  18. var jobComp = pair.Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(JobRoleComponent));
  19. Assert.Multiple(() =>
  20. {
  21. foreach (var (proto, comp) in pair.GetPrototypesWithComponent<MindRoleComponent>())
  22. {
  23. Assert.That(comp.AntagPrototype == null || comp.JobPrototype == null, $"Role {proto.ID} has both a job and antag prototype.");
  24. Assert.That(!comp.ExclusiveAntag || comp.Antag, $"Role {proto.ID} is marked as an exclusive antag, despite not being an antag.");
  25. Assert.That(comp.Antag || comp.AntagPrototype == null, $"Role {proto.ID} has an antag prototype, despite not being an antag.");
  26. if (comp.JobPrototype != null)
  27. Assert.That(proto.Components.ContainsKey(jobComp), $"Role {proto.ID} is a job, despite not having a job prototype.");
  28. // It is possible that this is meant to be supported? Though I would assume that it would be for
  29. // admin / prototype uploads, and that pre-defined roles should still check this.
  30. Assert.That(!comp.Antag || comp.AntagPrototype != null , $"Role {proto.ID} is an antag, despite not having a antag prototype.");
  31. }
  32. });
  33. await pair.CleanReturnAsync();
  34. }
  35. /// <summary>
  36. /// Check that any prototype with a <see cref="JobRoleComponent"/> also has a properly configured
  37. /// <see cref="MindRoleComponent"/>
  38. /// </summary>
  39. [Test]
  40. public async Task ValidateJobPrototypes()
  41. {
  42. await using var pair = await PoolManager.GetServerClient();
  43. var mindCompId = pair.Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(MindRoleComponent));
  44. Assert.Multiple(() =>
  45. {
  46. foreach (var (proto, comp) in pair.GetPrototypesWithComponent<JobRoleComponent>())
  47. {
  48. if (proto.Components.TryGetComponent(mindCompId, out var mindComp))
  49. Assert.That(((MindRoleComponent)mindComp).JobPrototype, Is.Not.Null);
  50. }
  51. });
  52. await pair.CleanReturnAsync();
  53. }
  54. /// <summary>
  55. /// Check that any prototype with a component that inherits from <see cref="BaseMindRoleComponent"/> also has a
  56. /// <see cref="MindRoleComponent"/>
  57. /// </summary>
  58. [Test]
  59. public async Task ValidateRolesHaveMindRoleComp()
  60. {
  61. await using var pair = await PoolManager.GetServerClient();
  62. var refMan = pair.Server.ResolveDependency<IReflectionManager>();
  63. var mindCompId = pair.Server.ResolveDependency<IComponentFactory>().GetComponentName(typeof(MindRoleComponent));
  64. var compTypes = refMan.GetAllChildren(typeof(BaseMindRoleComponent))
  65. .Append(typeof(RoleBriefingComponent))
  66. .Where(x => !x.IsAbstract);
  67. Assert.Multiple(() =>
  68. {
  69. foreach (var comp in compTypes)
  70. {
  71. foreach (var proto in pair.GetPrototypesWithComponent(comp))
  72. {
  73. Assert.That(proto.Components.ContainsKey(mindCompId), $"Role {proto.ID} does not have a {nameof(MindRoleComponent)} despite having a {comp.Name}");
  74. }
  75. }
  76. });
  77. await pair.CleanReturnAsync();
  78. }
  79. }