AlertOrderPrototypeTests.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using Content.Shared.Alert;
  5. using NUnit.Framework;
  6. using Robust.Shared.IoC;
  7. using Robust.Shared.Prototypes;
  8. using Robust.Shared.Serialization.Manager;
  9. namespace Content.Tests.Shared.Alert
  10. {
  11. [TestFixture, TestOf(typeof(AlertOrderPrototype))]
  12. public sealed class AlertOrderPrototypeTests : ContentUnitTest
  13. {
  14. const string PROTOTYPES = @"
  15. - type: alertOrder
  16. id: testAlertOrder
  17. order:
  18. - alertType: Handcuffed
  19. - alertType: Ensnared
  20. - category: Pressure
  21. - category: Hunger
  22. - alertType: Hot
  23. - alertType: Stun
  24. - alertType: LowPressure
  25. - category: Temperature
  26. - type: alert
  27. id: LowPressure
  28. icons: []
  29. category: Pressure
  30. - type: alert
  31. id: HighPressure
  32. icons: []
  33. category: Pressure
  34. - type: alert
  35. id: Peckish
  36. icons: []
  37. category: Hunger
  38. - type: alert
  39. id: Stun
  40. icons: []
  41. - type: alert
  42. id: Handcuffed
  43. icons: []
  44. - type: alert
  45. id: Ensnared
  46. icons: []
  47. - type: alert
  48. id: Hot
  49. icons: []
  50. category: Temperature
  51. - type: alert
  52. id: Cold
  53. icons: []
  54. category: Temperature
  55. - type: alert
  56. id: Weightless
  57. icons: []
  58. - type: alert
  59. id: PilotingShuttle
  60. icons: []
  61. ";
  62. [Test]
  63. public void TestAlertOrderPrototype()
  64. {
  65. IoCManager.Resolve<ISerializationManager>().Initialize();
  66. var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
  67. prototypeManager.Initialize();
  68. prototypeManager.LoadFromStream(new StringReader(PROTOTYPES));
  69. prototypeManager.ResolveResults();
  70. var alertOrder = prototypeManager.EnumeratePrototypes<AlertOrderPrototype>().FirstOrDefault();
  71. var alerts = prototypeManager.EnumeratePrototypes<AlertPrototype>();
  72. // ensure they sort according to our expected criteria
  73. var expectedOrder = new List<string>();
  74. expectedOrder.Add("Handcuffed");
  75. expectedOrder.Add("Ensnared");
  76. expectedOrder.Add("HighPressure");
  77. // stuff with only category + same category ordered by enum value
  78. expectedOrder.Add("Peckish");
  79. expectedOrder.Add("Hot");
  80. expectedOrder.Add("Stun");
  81. expectedOrder.Add("LowPressure");
  82. expectedOrder.Add("Cold");
  83. // stuff at end of list ordered by ID
  84. expectedOrder.Add("PilotingShuttle");
  85. expectedOrder.Add("Weightless");
  86. var actual = alerts.ToList();
  87. actual.Sort(alertOrder);
  88. Assert.That(actual.Select(a => a.ID).ToList(), Is.EqualTo(expectedOrder));
  89. }
  90. }
  91. }