Makes power test nullable (#3333)

* Makes power test nullable

* fix
This commit is contained in:
collinlunn
2021-02-20 15:49:12 -07:00
committed by GitHub
parent 008fee4eaf
commit f85d8435c1

View File

@@ -1,3 +1,4 @@
#nullable enable
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.GameObjects.Components; using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.Power;
@@ -120,9 +121,9 @@ namespace Content.IntegrationTests.Tests
var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes};
var server = StartServerDummyTicker(options); var server = StartServerDummyTicker(options);
PowerSupplierComponent supplier = null; PowerSupplierComponent supplier = default!;
PowerConsumerComponent consumer1 = null; PowerConsumerComponent consumer1 = default!;
PowerConsumerComponent consumer2 = null; PowerConsumerComponent consumer2 = default!;
server.Assert(() => server.Assert(() =>
{ {
@@ -135,14 +136,14 @@ namespace Content.IntegrationTests.Tests
var consumerEnt1 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 1)); var consumerEnt1 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 1));
var consumerEnt2 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 2)); var consumerEnt2 = entityMan.SpawnEntity("ConsumerDummy", grid.ToCoordinates(0, 2));
if (generatorEnt.TryGetComponent(out AnchorableComponent anchorable)) if (generatorEnt.TryGetComponent(out PhysicsComponent? physics))
{ {
anchorable.TryAnchor(null, force:true); physics.Anchored = true;
} }
Assert.That(generatorEnt.TryGetComponent(out supplier)); supplier = generatorEnt.GetComponent<PowerSupplierComponent>();
Assert.That(consumerEnt1.TryGetComponent(out consumer1)); consumer1 = consumerEnt1.GetComponent<PowerConsumerComponent>();
Assert.That(consumerEnt2.TryGetComponent(out consumer2)); consumer2 = consumerEnt2.GetComponent<PowerConsumerComponent>();
var supplyRate = 1000; //arbitrary amount of power supply var supplyRate = 1000; //arbitrary amount of power supply
@@ -171,8 +172,8 @@ namespace Content.IntegrationTests.Tests
var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes};
var server = StartServerDummyTicker(options); var server = StartServerDummyTicker(options);
BatteryComponent apcBattery = null; BatteryComponent apcBattery = default!;
PowerSupplierComponent substationSupplier = null; PowerSupplierComponent substationSupplier = default!;
server.Assert(() => server.Assert(() =>
{ {
@@ -185,14 +186,14 @@ namespace Content.IntegrationTests.Tests
var substationEnt = entityMan.SpawnEntity("SubstationDummy", grid.ToCoordinates(0, 1)); var substationEnt = entityMan.SpawnEntity("SubstationDummy", grid.ToCoordinates(0, 1));
var apcEnt = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 2)); var apcEnt = entityMan.SpawnEntity("ApcDummy", grid.ToCoordinates(0, 2));
Assert.That(generatorEnt.TryGetComponent<PowerSupplierComponent>(out var generatorSupplier)); var generatorSupplier = generatorEnt.GetComponent<PowerSupplierComponent>();
Assert.That(substationEnt.TryGetComponent(out substationSupplier)); substationSupplier = substationEnt.GetComponent<PowerSupplierComponent>();
Assert.That(substationEnt.TryGetComponent<BatteryStorageComponent>(out var substationStorage)); var substationStorage = substationEnt.GetComponent<BatteryStorageComponent>();
Assert.That(substationEnt.TryGetComponent<BatteryDischargerComponent>(out var substationDischarger)); var substationDischarger = substationEnt.GetComponent<BatteryDischargerComponent>();
Assert.That(apcEnt.TryGetComponent(out apcBattery)); apcBattery = apcEnt.GetComponent<BatteryComponent>();
Assert.That(apcEnt.TryGetComponent<BatteryStorageComponent>(out var apcStorage)); var apcStorage = apcEnt.GetComponent<BatteryStorageComponent>();
generatorSupplier.SupplyRate = 1000; //arbitrary nonzero amount of power generatorSupplier.SupplyRate = 1000; //arbitrary nonzero amount of power
substationStorage.ActiveDrawRate = 1000; //arbitrary nonzero power draw substationStorage.ActiveDrawRate = 1000; //arbitrary nonzero power draw
@@ -219,7 +220,7 @@ namespace Content.IntegrationTests.Tests
var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes}; var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes};
var server = StartServerDummyTicker(options); var server = StartServerDummyTicker(options);
PowerReceiverComponent receiver = null; PowerReceiverComponent receiver = default!;
server.Assert(() => server.Assert(() =>
{ {
@@ -233,16 +234,16 @@ namespace Content.IntegrationTests.Tests
var apcExtensionEnt = entityMan.SpawnEntity("ApcExtensionCableDummy", grid.ToCoordinates(0, 1)); var apcExtensionEnt = entityMan.SpawnEntity("ApcExtensionCableDummy", grid.ToCoordinates(0, 1));
var powerReceiverEnt = entityMan.SpawnEntity("PowerReceiverDummy", grid.ToCoordinates(0, 2)); var powerReceiverEnt = entityMan.SpawnEntity("PowerReceiverDummy", grid.ToCoordinates(0, 2));
Assert.That(apcEnt.TryGetComponent<ApcComponent>(out var apc)); var apc = apcEnt.GetComponent<ApcComponent>();
Assert.That(apcExtensionEnt.TryGetComponent<PowerProviderComponent>(out var provider)); var provider = apcExtensionEnt.GetComponent<PowerProviderComponent>();
Assert.That(powerReceiverEnt.TryGetComponent(out receiver)); receiver = powerReceiverEnt.GetComponent<PowerReceiverComponent>();
Assert.NotNull(apc.Battery); var battery = apcEnt.GetComponent<BatteryComponent>();
provider.PowerTransferRange = 5; //arbitrary range to reach receiver provider.PowerTransferRange = 5; //arbitrary range to reach receiver
receiver.PowerReceptionRange = 5; //arbitrary range to reach provider receiver.PowerReceptionRange = 5; //arbitrary range to reach provider
apc.Battery.MaxCharge = 10000; //arbitrary nonzero amount of charge battery.MaxCharge = 10000; //arbitrary nonzero amount of charge
apc.Battery.CurrentCharge = apc.Battery.MaxCharge; //fill battery battery.CurrentCharge = battery.MaxCharge; //fill battery
receiver.Load = 1; //arbitrary small amount of power receiver.Load = 1; //arbitrary small amount of power
}); });