Refactored integration tests to not use content entity prototypes (#2571)

* Refactored integration tests to not use content prototypes

* oops

* Apply suggestions from code review

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
DamianX
2020-11-18 15:30:36 +01:00
committed by GitHub
parent 501156f84c
commit 87e74c4494
17 changed files with 425 additions and 70 deletions

View File

@@ -15,10 +15,111 @@ namespace Content.IntegrationTests.Tests
[TestFixture]
public class PowerTest : ContentIntegrationTest
{
private const string PROTOTYPES = @"
- type: entity
name: GeneratorDummy
id: GeneratorDummy
components:
- type: NodeContainer
nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerSupplier
supplyRate: 3000
- type: Anchorable
- type: SnapGrid
offset: Center
- type: entity
name: ConsumerDummy
id: ConsumerDummy
components:
- type: SnapGrid
offset: Center
- type: NodeContainer
nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- type: PowerConsumer
drawRate: 50
- type: entity
name: SubstationDummy
id: SubstationDummy
components:
- type: Battery
maxCharge: 1000
startingCharge: 1000
- type: NodeContainer
nodes:
- !type:AdjacentNode
nodeGroupID: HVPower
- !type:AdjacentNode
nodeGroupID: MVPower
- type: PowerConsumer
- type: BatteryStorage
activeDrawRate: 1500
- type: PowerSupplier
voltage: Medium
- type: BatteryDischarger
activeSupplyRate: 1000
- type: SnapGrid
offset: Center
- type: entity
name: ApcDummy
id: ApcDummy
components:
- type: Battery
maxCharge: 10000
startingCharge: 10000
- type: BatteryStorage
activeDrawRate: 1000
- type: PowerProvider
voltage: Apc
- type: Apc
voltage: Apc
- type: PowerConsumer
voltage: Medium
- type: NodeContainer
nodes:
- !type:AdjacentNode
nodeGroupID: MVPower
- !type:AdjacentNode
nodeGroupID: Apc
- type: SnapGrid
offset: Center
- type: entity
name: ApcExtensionCableDummy
id: ApcExtensionCableDummy
components:
- type: NodeContainer
nodes:
- !type:AdjacentNode
nodeGroupID: Apc
- !type:AdjacentNode
nodeGroupID: WireNet
- type: PowerProvider
voltage: Apc
- type: Wire
wireType: Apc
- type: SnapGrid
offset: Center
- type: entity
name: PowerReceiverDummy
id: PowerReceiverDummy
components:
- type: PowerReceiver
- type: SnapGrid
offset: Center
";
[Test]
public async Task PowerNetTest()
{
var server = StartServerDummyTicker();
var options = new ServerIntegrationOptions{ExtraPrototypes = PROTOTYPES};
var server = StartServerDummyTicker(options);
PowerSupplierComponent supplier = null;
PowerConsumerComponent consumer1 = null;
@@ -31,9 +132,9 @@ namespace Content.IntegrationTests.Tests
mapMan.CreateMap(new MapId(1));
var grid = mapMan.CreateGrid(new MapId(1));
var generatorEnt = entityMan.SpawnEntity("DebugGenerator", grid.ToCoordinates());
var consumerEnt1 = entityMan.SpawnEntity("DebugConsumer", grid.ToCoordinates(0, 1));
var consumerEnt2 = entityMan.SpawnEntity("DebugConsumer", grid.ToCoordinates(0, 2));
var generatorEnt = entityMan.SpawnEntity("GeneratorDummy", grid.ToCoordinates());
var consumerEnt1 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 1));
var consumerEnt2 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 2));
if (generatorEnt.TryGetComponent(out AnchorableComponent anchorable))
{
@@ -68,7 +169,8 @@ namespace Content.IntegrationTests.Tests
[Test]
public async Task ApcChargingTest()
{
var server = StartServerDummyTicker();
var options = new ServerIntegrationOptions{ExtraPrototypes = PROTOTYPES};
var server = StartServerDummyTicker(options);
BatteryComponent apcBattery = null;
PowerSupplierComponent substationSupplier = null;
@@ -80,9 +182,9 @@ namespace Content.IntegrationTests.Tests
mapMan.CreateMap(new MapId(1));
var grid = mapMan.CreateGrid(new MapId(1));
var generatorEnt = entityMan.SpawnEntity("DebugGenerator", grid.ToCoordinates());
var substationEnt = entityMan.SpawnEntity("DebugSubstation", grid.ToCoordinates(0, 1));
var apcEnt = entityMan.SpawnEntity("DebugApc", grid.ToCoordinates(0, 2));
var generatorEnt = entityMan.SpawnEntity("GeneratorDummy", grid.ToCoordinates());
var substationEnt = entityMan.SpawnEntity("SubstationDummy", grid.ToCoordinates(0, 1));
var apcEnt = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 2));
Assert.That(generatorEnt.TryGetComponent<PowerSupplierComponent>(out var generatorSupplier));
@@ -115,7 +217,8 @@ namespace Content.IntegrationTests.Tests
[Test]
public async Task ApcNetTest()
{
var server = StartServerDummyTicker();
var options = new ServerIntegrationOptions{ExtraPrototypes = PROTOTYPES};
var server = StartServerDummyTicker(options);
PowerReceiverComponent receiver = null;
@@ -126,9 +229,9 @@ namespace Content.IntegrationTests.Tests
mapMan.CreateMap(new MapId(1));
var grid = mapMan.CreateGrid(new MapId(1));
var apcEnt = entityMan.SpawnEntity("DebugApc", grid.ToCoordinates(0, 0));
var apcExtensionEnt = entityMan.SpawnEntity("ApcExtensionCable", grid.ToCoordinates(0, 1));
var powerReceiverEnt = entityMan.SpawnEntity("DebugPowerReceiver", grid.ToCoordinates(0, 2));
var apcEnt = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 0));
var apcExtensionEnt = entityMan.SpawnEntity("ApcExtensionCableDummy", grid.ToCoordinates(0, 1));
var powerReceiverEnt = entityMan.SpawnEntity("PowerReceiverDummy", grid.ToCoordinates(0, 2));
Assert.That(apcEnt.TryGetComponent<ApcComponent>(out var apc));
Assert.That(apcExtensionEnt.TryGetComponent<PowerProviderComponent>(out var provider));