Skip to content

Commit d9ade6d

Browse files
committed
Added support for Magnets (landing gear) and added missing tests
1 parent 745a956 commit d9ade6d

File tree

7 files changed

+271
-4
lines changed

7 files changed

+271
-4
lines changed

EasyCommands.Tests/EasyCommands.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<Compile Include="ParameterParsingTests\TransferCommandProcessorTests.cs" />
132132
<Compile Include="ScriptTests\BlockHandlerTests\AirVentBlockTests.cs" />
133133
<Compile Include="ScriptTests\BlockHandlerTests\BeaconBlockTests.cs" />
134+
<Compile Include="ScriptTests\BlockHandlerTests\MagnetBlockTests.cs" />
135+
<Compile Include="ScriptTests\BlockHandlerTests\LandingGearBlockTests.cs" />
134136
<Compile Include="ScriptTests\BlockHandlerTests\ThrustBlockTests.cs" />
135137
<Compile Include="ScriptTests\BlockHandlerTests\ProgramBlockTests.cs" />
136138
<Compile Include="ScriptTests\BlockHandlerTests\DoorBlockTests.cs" />
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using Moq;
4+
using Sandbox.ModAPI.Ingame;
5+
using SpaceEngineers.Game.ModAPI.Ingame;
6+
7+
namespace EasyCommands.Tests.ScriptTests {
8+
[TestClass]
9+
public class LandingGearBlockTests {
10+
[TestMethod]
11+
public void TurnOnTheLandingGear() {
12+
using (ScriptTest test = new ScriptTest(@"turn on the ""test landing gear""")) {
13+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
14+
test.MockBlocksOfType("test landing gear", mockLandingGear);
15+
16+
test.RunUntilDone();
17+
18+
mockLandingGear.VerifySet(b => b.Enabled = true);
19+
}
20+
}
21+
22+
[TestMethod]
23+
public void TurnOffTheLandingGear() {
24+
using (ScriptTest test = new ScriptTest(@"turn off the ""test landing gear""")) {
25+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
26+
test.MockBlocksOfType("test landing gear", mockLandingGear);
27+
28+
test.RunUntilDone();
29+
30+
mockLandingGear.VerifySet(b => b.Enabled = false);
31+
}
32+
}
33+
34+
[TestMethod]
35+
public void IsTheLandingGearConnected() {
36+
using (ScriptTest test = new ScriptTest(@"Print ""Connected: "" + ""test landing gear"" is connected")) {
37+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
38+
test.MockBlocksOfType("test landing gear", mockLandingGear);
39+
mockLandingGear.Setup(b => b.IsLocked).Returns(true);
40+
41+
test.RunUntilDone();
42+
43+
Assert.AreEqual("Connected: True", test.Logger[0]);
44+
}
45+
}
46+
47+
[TestMethod]
48+
public void IsTheLandingGearLocked() {
49+
using (ScriptTest test = new ScriptTest(@"Print ""Locked: "" + ""test landing gear"" is locked")) {
50+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
51+
test.MockBlocksOfType("test landing gear", mockLandingGear);
52+
mockLandingGear.Setup(b => b.IsLocked).Returns(true);
53+
54+
test.RunUntilDone();
55+
56+
Assert.AreEqual("Locked: True", test.Logger[0]);
57+
}
58+
}
59+
60+
[TestMethod]
61+
public void ConnectTheLandingGear() {
62+
using (ScriptTest test = new ScriptTest(@"connect the ""test landing gear""")) {
63+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
64+
test.MockBlocksOfType("test landing gear", mockLandingGear);
65+
66+
test.RunUntilDone();
67+
68+
mockLandingGear.Verify(b => b.Lock());
69+
}
70+
}
71+
72+
[TestMethod]
73+
public void LockTheLandingGear() {
74+
using (ScriptTest test = new ScriptTest(@"lock the ""test landing gear""")) {
75+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
76+
test.MockBlocksOfType("test landing gear", mockLandingGear);
77+
78+
test.RunUntilDone();
79+
80+
mockLandingGear.Verify(b => b.Lock());
81+
}
82+
}
83+
84+
[TestMethod]
85+
public void DisconnectTheLandingGear() {
86+
using (ScriptTest test = new ScriptTest(@"disconnect the ""test landing gear""")) {
87+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
88+
test.MockBlocksOfType("test landing gear", mockLandingGear);
89+
90+
test.RunUntilDone();
91+
92+
mockLandingGear.Verify(b => b.Unlock());
93+
}
94+
}
95+
96+
[TestMethod]
97+
public void UnlockTheLandingGear() {
98+
using (ScriptTest test = new ScriptTest(@"unlock the ""test landing gear""")) {
99+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
100+
test.MockBlocksOfType("test landing gear", mockLandingGear);
101+
102+
test.RunUntilDone();
103+
104+
mockLandingGear.Verify(b => b.Unlock());
105+
}
106+
}
107+
108+
[TestMethod]
109+
public void IsLandingGearOnAuto() {
110+
using (ScriptTest test = new ScriptTest(@"Print ""Auto Lock: "" + the ""test landing gear"" is on auto")) {
111+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
112+
test.MockBlocksOfType("test landing gear", mockLandingGear);
113+
mockLandingGear.Setup(b => b.AutoLock).Returns(true);
114+
115+
test.RunUntilDone();
116+
117+
Assert.AreEqual("Auto Lock: True", test.Logger[0]);
118+
}
119+
}
120+
121+
[TestMethod]
122+
public void SetLandingGearToAuto() {
123+
using (ScriptTest test = new ScriptTest(@"set the ""test landing gear"" to auto")) {
124+
Mock<IMyLandingGear> mockLandingGear = new Mock<IMyLandingGear>();
125+
test.MockBlocksOfType("test landing gear", mockLandingGear);
126+
127+
test.RunUntilDone();
128+
129+
mockLandingGear.VerifySet(b => b.AutoLock = true);
130+
}
131+
}
132+
}
133+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using Moq;
4+
using Sandbox.ModAPI.Ingame;
5+
using SpaceEngineers.Game.ModAPI.Ingame;
6+
7+
namespace EasyCommands.Tests.ScriptTests {
8+
[TestClass]
9+
public class MagnetBlockTests {
10+
[TestMethod]
11+
public void TurnOnTheMagnet() {
12+
using (ScriptTest test = new ScriptTest(@"turn on the ""test magnet""")) {
13+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
14+
test.MockBlocksOfType("test magnet", mockMagnet);
15+
16+
test.RunUntilDone();
17+
18+
mockMagnet.VerifySet(b => b.Enabled = true);
19+
}
20+
}
21+
22+
[TestMethod]
23+
public void TurnOffTheMagnet() {
24+
using (ScriptTest test = new ScriptTest(@"turn off the ""test magnet""")) {
25+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
26+
test.MockBlocksOfType("test magnet", mockMagnet);
27+
28+
test.RunUntilDone();
29+
30+
mockMagnet.VerifySet(b => b.Enabled = false);
31+
}
32+
}
33+
34+
[TestMethod]
35+
public void IsTheMagnetConnected() {
36+
using (ScriptTest test = new ScriptTest(@"Print ""Connected: "" + ""test magnet"" is connected")) {
37+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
38+
test.MockBlocksOfType("test magnet", mockMagnet);
39+
mockMagnet.Setup(b => b.IsLocked).Returns(true);
40+
41+
test.RunUntilDone();
42+
43+
Assert.AreEqual("Connected: True", test.Logger[0]);
44+
}
45+
}
46+
47+
[TestMethod]
48+
public void IsTheMagnetLocked() {
49+
using (ScriptTest test = new ScriptTest(@"Print ""Locked: "" + ""test magnet"" is locked")) {
50+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
51+
test.MockBlocksOfType("test magnet", mockMagnet);
52+
mockMagnet.Setup(b => b.IsLocked).Returns(true);
53+
54+
test.RunUntilDone();
55+
56+
Assert.AreEqual("Locked: True", test.Logger[0]);
57+
}
58+
}
59+
60+
[TestMethod]
61+
public void ConnectTheMagnet() {
62+
using (ScriptTest test = new ScriptTest(@"connect the ""test magnet""")) {
63+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
64+
test.MockBlocksOfType("test magnet", mockMagnet);
65+
66+
test.RunUntilDone();
67+
68+
mockMagnet.Verify(b => b.Lock());
69+
}
70+
}
71+
72+
[TestMethod]
73+
public void LockTheMagnet() {
74+
using (ScriptTest test = new ScriptTest(@"lock the ""test magnet""")) {
75+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
76+
test.MockBlocksOfType("test magnet", mockMagnet);
77+
78+
test.RunUntilDone();
79+
80+
mockMagnet.Verify(b => b.Lock());
81+
}
82+
}
83+
84+
[TestMethod]
85+
public void DisconnectTheMagnet() {
86+
using (ScriptTest test = new ScriptTest(@"disconnect the ""test magnet""")) {
87+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
88+
test.MockBlocksOfType("test magnet", mockMagnet);
89+
90+
test.RunUntilDone();
91+
92+
mockMagnet.Verify(b => b.Unlock());
93+
}
94+
}
95+
96+
[TestMethod]
97+
public void UnlockTheMagnet() {
98+
using (ScriptTest test = new ScriptTest(@"unlock the ""test magnet""")) {
99+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
100+
test.MockBlocksOfType("test magnet", mockMagnet);
101+
102+
test.RunUntilDone();
103+
104+
mockMagnet.Verify(b => b.Unlock());
105+
}
106+
}
107+
108+
[TestMethod]
109+
public void IsMagnetOnAuto() {
110+
using (ScriptTest test = new ScriptTest(@"Print ""Auto Lock: "" + the ""test magnet"" is on auto")) {
111+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
112+
test.MockBlocksOfType("test magnet", mockMagnet);
113+
mockMagnet.Setup(b => b.AutoLock).Returns(true);
114+
115+
test.RunUntilDone();
116+
117+
Assert.AreEqual("Auto Lock: True", test.Logger[0]);
118+
}
119+
}
120+
121+
[TestMethod]
122+
public void SetMagnetToAuto() {
123+
using (ScriptTest test = new ScriptTest(@"set the ""test magnet"" to auto")) {
124+
Mock<IMyLandingGear> mockMagnet = new Mock<IMyLandingGear>();
125+
test.MockBlocksOfType("test magnet", mockMagnet);
126+
127+
test.RunUntilDone();
128+
129+
mockMagnet.VerifySet(b => b.AutoLock = true);
130+
}
131+
}
132+
}
133+
}

EasyCommands/BlockHandlers/BlockHandlers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static class BlockHandlerRegistry {
2929
{ Block.DRILL, new FunctionalBlockHandler<IMyShipDrill>() },
3030
{ Block.EJECTOR, new EjectorBlockHandler() },
3131
{ Block.ENGINE, new EngineBlockHandler<IMyPowerProducer>("Engine") },
32-
{ Block.GEAR, new LandingGearHandler() },
32+
{ Block.MAGNET, new LandingGearHandler() },
3333
{ Block.GENERATOR, new GasGeneratorHandler()},
3434
{ Block.GRAVITY_GENERATOR, new GravityGeneratorBlockHandler() },
3535
{ Block.GRAVITY_SPHERE, new SphericalGravityGeneratorBlockHandler() },

EasyCommands/BlockHandlers/LandingGearHandlers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public LandingGearHandler() {
2525
var lockHandler = BooleanHandler(b => b.IsLocked, (b, v) => { if (v) b.Lock(); else b.Unlock(); });
2626
AddPropertyHandler(Property.LOCKED, lockHandler);
2727
AddPropertyHandler(Property.CONNECTED, lockHandler);
28-
defaultPropertiesByPrimitive[Return.BOOLEAN] = Property.LOCKED;
2928
}
3029
}
3130
}

EasyCommands/CommandParsers/ParameterParsers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void InitializeParsers() {
243243
AddBlockWords(Words("turret"), Block.TURRET);
244244
AddBlockWords(Words("generator"), Block.GENERATOR);
245245
AddBlockWords(Words("tank"), Block.TANK);
246-
AddBlockWords(Words("gear"), Block.GEAR);
246+
AddBlockWords(Words("magnet", "gear"), Block.MAGNET);
247247
AddBlockWords(Words("battery"), Words("batteries"), Block.BATTERY);
248248
AddBlockWords(Words("chute", "parachute"), Block.PARACHUTE);
249249
AddBlockWords(Words("wheel"), Words("wheels", "suspension"), Block.SUSPENSION);

EasyCommands/Common/Types.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ partial class Program {
2323
public enum LogLevel { DEBUG, INFO, SCRIPT_ONLY }
2424
#endregion
2525

26-
public enum Block { PISTON, ROTOR, PROGRAM, TIMER, LIGHT, PROJECTOR, MERGE, CONNECTOR, WELDER, GRINDER, DOOR, DISPLAY, SOUND, CAMERA, SENSOR, BEACON, ANTENNA, COCKPIT, REMOTE, THRUSTER, AIRVENT, GUN, GENERATOR, TANK, GEAR, BATTERY, PARACHUTE, SUSPENSION, DETECTOR, DRILL, ENGINE, SORTER, TURRET, GYROSCOPE, GRAVITY_GENERATOR, GRAVITY_SPHERE, CARGO, WARHEAD, ASSEMBLER, EJECTOR, COLLECTOR, DECOY, HINGE, JUMPDRIVE, LASER_ANTENNA, TERMINAL, REFINERY, REACTOR, TURBINE, SOLAR_PANEL }
26+
public enum Block { PISTON, ROTOR, PROGRAM, TIMER, LIGHT, PROJECTOR, MERGE, CONNECTOR, WELDER, GRINDER, DOOR, DISPLAY, SOUND, CAMERA, SENSOR, BEACON, ANTENNA, COCKPIT, REMOTE, THRUSTER, AIRVENT, GUN, GENERATOR, TANK, MAGNET, BATTERY, PARACHUTE, SUSPENSION, DETECTOR, DRILL, ENGINE, SORTER, TURRET, GYROSCOPE, GRAVITY_GENERATOR, GRAVITY_SPHERE, CARGO, WARHEAD, ASSEMBLER, EJECTOR, COLLECTOR, DECOY, HINGE, JUMPDRIVE, LASER_ANTENNA, TERMINAL, REFINERY, REACTOR, TURBINE, SOLAR_PANEL }
2727
public enum Property { ENABLE, POWER, CONNECTED, LOCKED, COMPLETE, OPEN, TRIGGER, SUPPLY, AUTO, OVERRIDE, LEVEL, ANGLE, VELOCITY, RATIO, FONT, VOLUME, RANGE, INPUT, ROLL_INPUT, NAME, RUN, TEXT, COLOR, BACKGROUND, MEDIA, MEDIA_LIST, INTERVAL, OFFSET, INTENSITY, FALLOFF, POSITION, DIRECTION, TARGET, WAYPOINTS, TARGET_VELOCITY, STRENGTH, COUNTDOWN, SILENCE, SHOW, PROPERTIES, ACTIONS, NAMES }
2828
public enum ValueProperty { AMOUNT, CREATE, DESTROY, PROPERTY, ACTION };
2929
public enum Direction { UP, DOWN, LEFT, RIGHT, FORWARD, BACKWARD, CLOCKWISE, COUNTERCLOCKWISE, NONE }

0 commit comments

Comments
 (0)