Files
crystall-punk-14/Content.IntegrationTests/Tests/Utility/EntityWhitelistTest.cs

116 lines
3.7 KiB
C#
Raw Normal View History

using System.Linq;
using System.Threading.Tasks;
using Content.Shared.Containers.ItemSlots;
2021-06-09 22:19:39 +02:00
using Content.Shared.Whitelist;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
namespace Content.IntegrationTests.Tests.Utility
{
[TestFixture]
[TestOf(typeof(EntityWhitelist))]
public sealed class EntityWhitelistTest : ContentIntegrationTest
{
private const string InvalidComponent = "Sprite";
private const string ValidComponent = "Physics";
private static readonly string Prototypes = $@"
- type: Tag
id: ValidTag
- type: Tag
id: InvalidTag
- type: entity
id: WhitelistDummy
components:
- type: ItemSlots
slots:
slotName:
whitelist:
prototypes:
- ValidPrototypeDummy
components:
- {ValidComponent}
tags:
- ValidTag
- type: entity
id: InvalidComponentDummy
components:
- type: {InvalidComponent}
- type: entity
id: InvalidTagDummy
components:
- type: Tag
tags:
- InvalidTag
- type: entity
id: ValidComponentDummy
components:
- type: {ValidComponent}
- type: entity
id: ValidTagDummy
components:
- type: Tag
tags:
- ValidTag";
[Test]
public async Task Test()
{
var serverOptions = new ServerContentIntegrationOption {ExtraPrototypes = Prototypes};
var server = StartServer(serverOptions);
await server.WaitIdleAsync();
var mapManager = server.ResolveDependency<IMapManager>();
2021-12-05 18:09:01 +01:00
var sEntities = server.ResolveDependency<IEntityManager>();
await server.WaitAssertion(() =>
{
Add test pooling (#4961) * Add test pooling * WIP test pooling changes * Fix Destructible tests * Don't pool unpooled or dummy ticker instances * Change ServerPathfindingDebugSystem to replace existing entries * Fix SaveLoadSaveTest comment * Don't pool StartTest * Comment out global setup * Fix puddle tests * Move SolarPanelComponent initialize to PowerSolarSystem OnMapInit * Update RobustToolbox * Finish fixing tests, make test threads background threads * Bring back pooling * Fix nullable * Update RobustToolbox * Set cvars on server return * Un-pool tests with custom cvars * Update RobustToolbox * Update RobustToolbox * Change where the main tile coordinates are * Remove DisposalUnitTest grid check * Fix test pooling being a fickle bitch * Fix EntitySystemExtensionsTest * Update RobustToolbox * Update RobustToolbox * Make nullable pool settings true * Update RobustToolbox * Wait other way around * We are unitystation now * Update RobustToolbox * Create global setup * Pool some more tests * Fix not properly disconnecting clients before restarting the round * Give more info on ran tests * Standardize default test cvars * Update RobustToolbox * Update RobustToolbox * Pool clients * Fix test order issue * Fix cvars in character creation test not being set properly * Update RobustToolbox * Update RobustToolbox * Rider shut * Update RobustToolbox * Format tests ran better * Update RobustToolbox * Reset RobustToolbox * Reset RobustToolbox harder * Fix one instance of test order causing destructible tests to fail
2021-11-06 11:49:59 +01:00
var mapId = GetMainMapId(mapManager);
var mapCoordinates = new MapCoordinates(0, 0, mapId);
2021-12-05 18:09:01 +01:00
var validComponent = sEntities.SpawnEntity("ValidComponentDummy", mapCoordinates);
var validTag = sEntities.SpawnEntity("ValidTagDummy", mapCoordinates);
2021-12-05 18:09:01 +01:00
var invalidComponent = sEntities.SpawnEntity("InvalidComponentDummy", mapCoordinates);
var invalidTag = sEntities.SpawnEntity("InvalidTagDummy", mapCoordinates);
// Test instantiated on its own
var whitelistInst = new EntityWhitelist
{
Components = new[] {$"{ValidComponent}"},
Tags = new[] {"ValidTag"}
};
whitelistInst.UpdateRegistrations();
Assert.That(whitelistInst, Is.Not.Null);
Assert.That(whitelistInst.Components, Is.Not.Null);
Assert.That(whitelistInst.Tags, Is.Not.Null);
Assert.That(whitelistInst.IsValid(validComponent), Is.True);
Assert.That(whitelistInst.IsValid(validTag), Is.True);
Assert.That(whitelistInst.IsValid(invalidComponent), Is.False);
Assert.That(whitelistInst.IsValid(invalidTag), Is.False);
// Test from serialized
2021-12-05 18:09:01 +01:00
var dummy = sEntities.SpawnEntity("WhitelistDummy", mapCoordinates);
var whitelistSer = sEntities.GetComponent<ItemSlotsComponent>(dummy).Slots.Values.First().Whitelist;
Assert.That(whitelistSer, Is.Not.Null);
Assert.That(whitelistSer.Components, Is.Not.Null);
Assert.That(whitelistSer.Tags, Is.Not.Null);
Assert.That(whitelistSer.IsValid(validComponent), Is.True);
Assert.That(whitelistSer.IsValid(validTag), Is.True);
Assert.That(whitelistSer.IsValid(invalidComponent), Is.False);
Assert.That(whitelistSer.IsValid(invalidTag), Is.False);
});
}
}
}