AlertManagerTests.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.IO;
  2. using Content.Client.Alerts;
  3. using Content.Shared.Alert;
  4. using NUnit.Framework;
  5. using Robust.Shared.GameObjects;
  6. using Robust.Shared.IoC;
  7. using Robust.Shared.Prototypes;
  8. using Robust.Shared.Reflection;
  9. using Robust.Shared.Serialization.Manager;
  10. using Robust.Shared.Utility;
  11. using Robust.UnitTesting;
  12. namespace Content.Tests.Shared.Alert
  13. {
  14. [TestFixture, TestOf(typeof(AlertsSystem))]
  15. public sealed class AlertManagerTests : RobustUnitTest
  16. {
  17. const string PROTOTYPES = @"
  18. - type: alert
  19. id: LowPressure
  20. icons:
  21. - /Textures/Interface/Alerts/Pressure/lowpressure.png
  22. - type: alert
  23. id: HighPressure
  24. icons:
  25. - /Textures/Interface/Alerts/Pressure/highpressure.png
  26. ";
  27. [Test]
  28. [Ignore("There is no way to load extra Systems in a unit test, fixing RobustUnitTest is out of scope.")]
  29. public void TestAlertManager()
  30. {
  31. var entManager = IoCManager.Resolve<IEntityManager>();
  32. var sysManager = entManager.EntitySysManager;
  33. sysManager.LoadExtraSystemType<ClientAlertsSystem>();
  34. var alertsSystem = sysManager.GetEntitySystem<ClientAlertsSystem>();
  35. IoCManager.Resolve<ISerializationManager>().Initialize();
  36. var reflection = IoCManager.Resolve<IReflectionManager>();
  37. reflection.LoadAssemblies();
  38. var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
  39. prototypeManager.Initialize();
  40. prototypeManager.LoadFromStream(new StringReader(PROTOTYPES));
  41. Assert.That(alertsSystem.TryGet("LowPressure", out var lowPressure));
  42. Assert.That(lowPressure!.Icons[0], Is.EqualTo(new SpriteSpecifier.Texture(new ("/Textures/Interface/Alerts/Pressure/lowpressure.png"))));
  43. Assert.That(alertsSystem.TryGet("HighPressure", out var highPressure));
  44. Assert.That(highPressure!.Icons[0], Is.EqualTo(new SpriteSpecifier.Texture(new ("/Textures/Interface/Alerts/Pressure/highpressure.png"))));
  45. Assert.That(alertsSystem.TryGet("LowPressure", out lowPressure));
  46. Assert.That(lowPressure!.Icons[0], Is.EqualTo(new SpriteSpecifier.Texture(new ("/Textures/Interface/Alerts/Pressure/lowpressure.png"))));
  47. Assert.That(alertsSystem.TryGet("HighPressure", out highPressure));
  48. Assert.That(highPressure!.Icons[0], Is.EqualTo(new SpriteSpecifier.Texture(new ("/Textures/Interface/Alerts/Pressure/highpressure.png"))));
  49. }
  50. }
  51. }