2021-02-16 20:14:12 +01:00
|
|
|
|
using System.IO;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Dataset;
|
|
|
|
|
|
using Content.Shared.Random.Helpers;
|
2021-02-16 20:14:12 +01:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
using Robust.Shared.Random;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager;
|
2021-02-16 20:14:12 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Tests.Shared.Utility
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
|
[TestOf(typeof(SharedRandomExtensions))]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class RandomExtensionsTests : ContentUnitTest
|
2021-02-16 20:14:12 +01:00
|
|
|
|
{
|
|
|
|
|
|
private const string TestDatasetId = "TestDataset";
|
|
|
|
|
|
|
|
|
|
|
|
private static readonly string Prototypes = $@"
|
|
|
|
|
|
- type: dataset
|
|
|
|
|
|
id: {TestDatasetId}
|
|
|
|
|
|
values:
|
|
|
|
|
|
- A";
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void RandomDataSetValueTest()
|
|
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
IoCManager.Resolve<ISerializationManager>().Initialize();
|
2021-02-16 20:14:12 +01:00
|
|
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
2021-09-04 14:13:34 +10:00
|
|
|
|
prototypeManager.Initialize();
|
2021-02-16 20:14:12 +01:00
|
|
|
|
|
|
|
|
|
|
prototypeManager.LoadFromStream(new StringReader(Prototypes));
|
2022-04-03 02:01:22 +02:00
|
|
|
|
prototypeManager.ResolveResults();
|
2021-02-16 20:14:12 +01:00
|
|
|
|
|
|
|
|
|
|
var dataSet = prototypeManager.Index<DatasetPrototype>(TestDatasetId);
|
|
|
|
|
|
var random = IoCManager.Resolve<IRobustRandom>();
|
|
|
|
|
|
var id = random.Pick(dataSet);
|
|
|
|
|
|
|
2024-01-12 23:22:01 +01:00
|
|
|
|
Assert.That(id, Is.Not.Null);
|
2021-02-16 20:14:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|