Files
Delta-v/Content.IntegrationTests/Tests/Power/PowerStateTest.cs
Moony 6656adc083 Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-06-29 12:44:18 +02:00

182 lines
6.2 KiB
C#

using Content.IntegrationTests.Fixtures;
using Content.Shared.Coordinates;
using Content.Shared.Power.Components;
using Content.Shared.Power.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.Power;
[TestFixture]
public sealed class PowerStateTest : GameTest
{
[TestPrototypes]
private const string Prototypes = @"
- type: entity
id: PowerStateApcReceiverDummy
components:
- type: ApcPowerReceiver
- type: ExtensionCableReceiver
- type: Transform
anchored: true
- type: PowerState
isWorking: false
idlePowerDraw: 10
workingPowerDraw: 50
";
/// <summary>
/// Asserts that switching from idle to working updates the power receiver load to the working draw.
/// </summary>
[Test]
public async Task SetWorkingState_IdleToWorking_UpdatesLoad()
{
var pair = Pair;
var server = pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entManager = server.ResolveDependency<IEntityManager>();
var mapSys = entManager.System<SharedMapSystem>();
await server.WaitAssertion(() =>
{
mapSys.CreateMap(out var mapId);
var grid = mapManager.CreateGridEntity(mapId);
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
var ent = entManager.SpawnEntity("PowerStateApcReceiverDummy", grid.Owner.ToCoordinates());
var receiver = entManager.GetComponent<Server.Power.Components.ApcPowerReceiverComponent>(ent);
var powerState = entManager.GetComponent<PowerStateComponent>(ent);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.False);
Assert.That(receiver.Load, Is.EqualTo(powerState.IdlePowerDraw).Within(0.01f));
});
var system = entManager.System<SharedPowerStateSystem>();
system.SetWorkingState((ent, powerState), true);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.True);
Assert.That(receiver.Load, Is.EqualTo(powerState.WorkingPowerDraw).Within(0.01f));
});
});
}
/// <summary>
/// Asserts that switching from working to idle updates the power receiver load to the idle draw.
/// </summary>
[Test]
public async Task SetWorkingState_WorkingToIdle_UpdatesLoad()
{
var pair = Pair;
var server = pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entManager = server.ResolveDependency<IEntityManager>();
var mapSys = entManager.System<SharedMapSystem>();
await server.WaitAssertion(() =>
{
mapSys.CreateMap(out var mapId);
var grid = mapManager.CreateGridEntity(mapId);
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
var ent = entManager.SpawnEntity("PowerStateApcReceiverDummy", grid.Owner.ToCoordinates());
var receiver = entManager.GetComponent<Server.Power.Components.ApcPowerReceiverComponent>(ent);
var powerState = entManager.GetComponent<PowerStateComponent>(ent);
var system = entManager.System<SharedPowerStateSystem>();
Entity<PowerStateComponent> newEnt = (ent, powerState);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.False);
Assert.That(receiver.Load, Is.EqualTo(powerState.IdlePowerDraw).Within(0.01f));
});
system.SetWorkingState(newEnt, true);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.True);
Assert.That(receiver.Load, Is.EqualTo(powerState.WorkingPowerDraw).Within(0.01f));
});
system.SetWorkingState(newEnt, false);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.False);
Assert.That(receiver.Load, Is.EqualTo(powerState.IdlePowerDraw).Within(0.01f));
});
});
}
/// <summary>
/// Asserts that setting the working state to the current state does not change the power receiver load.
/// </summary>
[Test]
public async Task SetWorkingState_AlreadyInState_NoChange()
{
var pair = Pair;
var server = pair.Server;
var mapManager = server.ResolveDependency<IMapManager>();
var entManager = server.ResolveDependency<IEntityManager>();
var mapSys = entManager.System<SharedMapSystem>();
await server.WaitAssertion(() =>
{
mapSys.CreateMap(out var mapId);
var grid = mapManager.CreateGridEntity(mapId);
mapSys.SetTile(grid, Vector2i.Zero, new Tile(1));
var ent = entManager.SpawnEntity("PowerStateApcReceiverDummy", grid.Owner.ToCoordinates());
var receiver = entManager.GetComponent<Server.Power.Components.ApcPowerReceiverComponent>(ent);
var powerState = entManager.GetComponent<PowerStateComponent>(ent);
var system = entManager.System<SharedPowerStateSystem>();
Entity<PowerStateComponent> valueTuple = (ent, powerState);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.False);
Assert.That(receiver.Load, Is.EqualTo(powerState.IdlePowerDraw).Within(0.01f));
});
system.SetWorkingState(valueTuple, false);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.False);
Assert.That(receiver.Load, Is.EqualTo(powerState.IdlePowerDraw).Within(0.01f));
});
system.SetWorkingState(valueTuple, true);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.True);
Assert.That(receiver.Load, Is.EqualTo(powerState.WorkingPowerDraw).Within(0.01f));
});
system.SetWorkingState(valueTuple, true);
Assert.Multiple(() =>
{
Assert.That(powerState.IsWorking, Is.True);
Assert.That(receiver.Load, Is.EqualTo(powerState.WorkingPowerDraw).Within(0.01f));
});
});
}
}