1
0

LocalizedDatasetPrototypeTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using Content.Shared.Dataset;
  3. using NUnit.Framework;
  4. using Robust.Shared.Collections;
  5. using Robust.Shared.IoC;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Serialization.Manager;
  8. namespace Content.Tests.Shared;
  9. [TestFixture]
  10. [TestOf(typeof(LocalizedDatasetPrototype))]
  11. public sealed class LocalizedDatasetPrototypeTest : ContentUnitTest
  12. {
  13. private IPrototypeManager _prototypeManager;
  14. [OneTimeSetUp]
  15. public void OneTimeSetup()
  16. {
  17. IoCManager.Resolve<ISerializationManager>().Initialize();
  18. _prototypeManager = IoCManager.Resolve<IPrototypeManager>();
  19. _prototypeManager.Initialize();
  20. _prototypeManager.LoadString(TestPrototypes);
  21. _prototypeManager.ResolveResults();
  22. }
  23. private const string TestPrototypes = @"
  24. - type: localizedDataset
  25. id: Test
  26. values:
  27. prefix: test-dataset-
  28. count: 4
  29. ";
  30. [Test]
  31. public void LocalizedDatasetTest()
  32. {
  33. var testPrototype = _prototypeManager.Index<LocalizedDatasetPrototype>("Test");
  34. var values = new ValueList<string>();
  35. foreach (var value in testPrototype.Values)
  36. {
  37. values.Add(value);
  38. }
  39. // Make sure we get the right number of values
  40. Assert.That(values, Has.Count.EqualTo(4));
  41. // Make sure indexing works as expected
  42. Assert.That(testPrototype.Values[0], Is.EqualTo("test-dataset-1"));
  43. Assert.That(testPrototype.Values[1], Is.EqualTo("test-dataset-2"));
  44. Assert.That(testPrototype.Values[2], Is.EqualTo("test-dataset-3"));
  45. Assert.That(testPrototype.Values[3], Is.EqualTo("test-dataset-4"));
  46. Assert.Throws<IndexOutOfRangeException>(() => { var x = testPrototype.Values[4]; });
  47. Assert.Throws<IndexOutOfRangeException>(() => { var x = testPrototype.Values[-1]; });
  48. // Make sure that the enumerator gets all of the values
  49. Assert.That(testPrototype.Values[^1], Is.EqualTo("test-dataset-4"));
  50. }
  51. }