Files
tbd-station-14/Content.IntegrationTests/Tests/AI/BehaviorSetsTest.cs
wrexbe 81e3b2da88 Make tests faster (#8737)
* Test changes

* Make finding the test tile a little smarter
2022-06-19 20:22:28 -07:00

63 lines
2.3 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.AI.Utility;
using Content.Server.AI.Utility.Actions;
using Content.Server.AI.Utility.AiLogic;
using NUnit.Framework;
using Robust.Shared.Prototypes;
using Robust.Shared.Reflection;
namespace Content.IntegrationTests.Tests.AI
{
[TestFixture]
[TestOf(typeof(BehaviorSetPrototype))]
public sealed class BehaviorSetsTest
{
[Test]
public async Task TestBehaviorSets()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings{NoClient = true});
var server = pairTracker.Pair.Server;
var protoManager = server.ResolveDependency<IPrototypeManager>();
var reflectionManager = server.ResolveDependency<IReflectionManager>();
Dictionary<string, List<string>> behaviorSets = new();
// Test that all BehaviorSet actions exist.
await server.WaitAssertion(() =>
{
foreach (var proto in protoManager.EnumeratePrototypes<BehaviorSetPrototype>())
{
behaviorSets[proto.ID] = proto.Actions.ToList();
foreach (var action in proto.Actions)
{
if (!reflectionManager.TryLooseGetType(action, out var actionType) ||
!typeof(IAiUtility).IsAssignableFrom(actionType))
{
Assert.Fail($"Action {action} is not valid within BehaviorSet {proto.ID}");
}
}
}
});
// Test that all BehaviorSets on NPCs exist.
await server.WaitAssertion(() =>
{
foreach (var entity in protoManager.EnumeratePrototypes<EntityPrototype>())
{
if (!entity.TryGetComponent<UtilityAi>("UtilityAI", out var npcNode)) continue;
foreach (var entry in npcNode.BehaviorSets)
{
Assert.That(behaviorSets.ContainsKey(entry), $"BehaviorSet {entry} in entity {entity.ID} not found");
}
}
});
await pairTracker.CleanReturnAsync();
}
}
}