public void conditionalVelocityAndSoundBlockTest() { String script = @" :reverseSirens if ""rover cockpit"" backwards velocity > 1 if ""reverse sirens"" are off turn on the ""reverse sirens"" else turn off the ""reverse sirens"" "; using (var test = new ScriptTest(script)) { var mockRoverCockpit = new Mock <IMyCockpit>(); mockRoverCockpit.Setup(b => b.WorldMatrix).Returns(MatrixD.CreateWorld(Vector3D.Zero)); mockRoverCockpit.Setup(b => b.GetShipVelocities()).Returns(new MyShipVelocities(new Vector3D(0, 0, 2), Vector3D.Zero)); var mockReverseSirens = new Mock <IMySoundBlock>(); mockReverseSirens.Setup(b => b.CustomData).Returns("Playing=False"); test.MockBlocksOfType("rover cockpit", mockRoverCockpit); test.MockBlocksInGroup("reverse sirens", mockReverseSirens); test.RunUntilDone(); mockReverseSirens.Verify(b => b.Play(), Times.Once); } }
public void detonateTheBomb() { String script = @" detonate the ""warheads"" "; using (ScriptTest test = new ScriptTest(script)) { var mockWarhead = new Mock <IMyWarhead>(); test.MockBlocksInGroup("warheads", mockWarhead); test.RunUntilDone(); mockWarhead.Verify(b => b.Detonate()); } }
public void DisableTurretsIdleRotation() { String script = @" set the ""turrets"" auto to false "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); test.RunUntilDone(); mockTurret.VerifySet(b => b.EnableIdleRotation = false); } }
public void SetTurretTargetVelocityUsingCustomTarget() { String script = @" set the ""turrets"" targetVelocity to ""1:2:3"" "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.CustomData).Returns("target=4:5:6"); test.RunUntilDone(); mockTurret.Verify(b => b.TrackTarget(new Vector3D(4, 5, 6), new Vector3D(1, 2, 3))); } }
public void UseVariableAsImplicitBlockSelector() { String script = @" assign ""myLights"" to 'test lights' turn on $myLights "; using (ScriptTest test = new ScriptTest(script)) { var mockLight = new Mock <IMyLightingBlock>(); test.MockBlocksInGroup("test lights", mockLight); test.RunUntilDone(); mockLight.VerifySet(b => b.Enabled = true); } }
public void SorterCanDrain() { String script = @" :main drain the ""sorters"" "; using (ScriptTest test = new ScriptTest(script)) { var mockSorter = new Mock <IMyConveyorSorter>(); test.MockBlocksInGroup("sorters", mockSorter); test.RunOnce(); mockSorter.VerifySet(s => s.DrainAll = true); } }
public void FireTheTurrets() { String script = @" tell the ""turrets"" to shoot "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); var turretFire = MockCalledAction(mockTurret, "Shoot_On"); test.RunUntilDone(); turretFire.Verify(b => b.Apply(mockTurret.Object)); } }
public void GetTurretTargetFromCustomData() { String script = @" print the ""turrets"" target "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.CustomData).Returns("target=1:2:3"); test.RunUntilDone(); Assert.AreEqual(1, test.Logger.Count); Assert.AreEqual("1:2:3", test.Logger[0]); } }
public void TurretIsLockedOnTarget() { String script = @" if any ""turrets"" is locked Print ""Locked On Target"" "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.IsAimed).Returns(true); test.RunUntilDone(); Assert.AreEqual(1, test.Logger.Count); Assert.AreEqual("Locked On Target", test.Logger[0]); } }
public void ResetTurretTarget() { String script = @" unlock the ""turrets"" "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.CustomData).Returns(""); mockTurret.Setup(b => b.EnableIdleRotation).Returns(true); test.RunUntilDone(); mockTurret.Verify(b => b.ResetTargetingToDefault()); mockTurret.VerifySet(b => b.EnableIdleRotation = true); } }
public void GetTurretNoTargetReturnsZeroVector() { String script = @" print the ""turrets"" target "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.CustomData).Returns(""); mockTurret.Setup(b => b.HasTarget).Returns(false); test.RunUntilDone(); Assert.AreEqual(1, test.Logger.Count); Assert.AreEqual("0:0:0", test.Logger[0]); } }
public void TurretsAreFiring() { String script = @" if the ""turrets"" are shooting print ""Get Some!"" "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.IsShooting).Returns(true); test.RunUntilDone(); Assert.AreEqual(1, test.Logger.Count); Assert.AreEqual("Get Some!", test.Logger[0]); } }
public void GetTurretTargetFromTargetedEntity() { String script = @" print the ""turrets"" target "; using (ScriptTest test = new ScriptTest(script)) { var mockTurret = new Mock <IMyLargeTurretBase>(); test.MockBlocksInGroup("turrets", mockTurret); mockTurret.Setup(b => b.CustomData).Returns(""); mockTurret.Setup(b => b.HasTarget).Returns(true); mockTurret.Setup(b => b.GetTargetedEntity()).Returns(MockDetectedEntity(new Vector3D(1, 2, 3))); test.RunUntilDone(); Assert.AreEqual(1, test.Logger.Count); Assert.AreEqual("1:2:3", test.Logger[0]); } }
public void SorterIsDraining() { String script = @" :main if ""sorters"" are draining Print ""Call a plumber, dude"" "; using (ScriptTest test = new ScriptTest(script)) { var mockSorter = new Mock <IMyConveyorSorter>(); mockSorter.Setup(s => s.DrainAll).Returns(true); test.MockBlocksInGroup("sorters", mockSorter); test.RunOnce(); Assert.IsTrue(test.Logger.Contains("Call a plumber, dude")); mockSorter.Verify(s => s.DrainAll); } }
public void UseVariableAsImplicitBlockSelectorInConditionAndBlockCommand() { String script = @" assign ""myLights"" to 'test lights' if $myLights are on Print 'You Left The Lights On' turn off $myLights "; using (ScriptTest test = new ScriptTest(script)) { var mockLight = new Mock <IMyLightingBlock>(); test.MockBlocksInGroup("test lights", mockLight); mockLight.Setup(b => b.Enabled).Returns(true); test.RunUntilDone(); mockLight.VerifySet(b => b.Enabled = false); Assert.AreEqual(1, test.Logger.Count); Assert.AreEqual("You Left The Lights On", test.Logger[0]); } }
public void BlocksAloneAndInGroups() { String script = @" :lightshow set the ""single light"" intensity to 10 set the ""hangar lights"" blinkInterval to 0.5 set the ""hangar lights"" blinkOffset to 0.25 turn on the ""hangar lights"" "; using (ScriptTest test = new ScriptTest(script)) { // In this test, single light and other light are both in // a group called "hangar lights" // We want to ensure that we're manipulating both lights when we // perform commands on the group, but that we can still interact // with just one of the lights when we want to var mockSingleLight = new Mock <IMyLightingBlock>(); var mockOtherLight = new Mock <IMyLightingBlock>(); test.MockBlocksInGroup("hangar lights", mockSingleLight, mockOtherLight); test.MockBlocksOfType("other light", mockOtherLight); test.MockBlocksOfType("single light", mockSingleLight); test.RunUntilDone(); mockSingleLight.VerifySet(b => b.Intensity = 10f); mockSingleLight.VerifySet(b => b.BlinkIntervalSeconds = 0.5f); mockSingleLight.VerifySet(b => b.BlinkOffset = 0.25f); mockOtherLight.VerifySet(b => b.BlinkIntervalSeconds = 0.5f); mockOtherLight.VerifySet(b => b.BlinkOffset = 0.25f); mockSingleLight.VerifySet(b => b.Enabled = true); mockOtherLight.VerifySet(b => b.Enabled = true); // We should have never manipulated the intensity of "other light" mockOtherLight.VerifySet(b => b.Intensity = 10f, Times.Never); } }
public void SensorTriggeredOpensTheOuterDoor() { using (var test = new ScriptTest(script)) { var mockSensor = new Mock <IMySensorBlock>(); var mockExteriorDoor = new Mock <IMyDoor>(); var mockInteriorDoor = new Mock <IMyDoor>(); var mockAirVent = new Mock <IMyAirVent>(); test.MockBlocksOfType("Air Lock Sensor", mockSensor); test.MockBlocksInGroup("Exterior Doors", mockExteriorDoor); test.MockBlocksInGroup("Interior Doors", mockInteriorDoor); test.MockBlocksOfType("Air Lock Vent", mockAirVent); //Setup, nothing happens first tick test.RunOnce(); //Close Inner Doors mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Open); test.RunOnce(); mockInteriorDoor.Verify(b => b.CloseDoor()); mockSensor.Verify(b => b.IsActive); //Wait For Inner Doors To Close mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closing); test.RunOnce(); mockInteriorDoor.Verify(b => b.CloseDoor()); mockSensor.Verify(b => b.IsActive); //Depressurize the Air Vent mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closed); mockAirVent.Setup(b => b.GetOxygenLevel()).Returns(1); test.RunOnce(); mockSensor.Verify(b => b.IsActive); mockAirVent.VerifySet(b => b.Depressurize = true); //Wait for the Air Vent to Depressurize mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closed); mockAirVent.Setup(b => b.GetOxygenLevel()).Returns(0.5f); test.RunOnce(); mockSensor.Verify(b => b.IsActive); mockAirVent.VerifySet(b => b.Depressurize = true); //Open The Outer Doors mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closed); mockAirVent.Setup(b => b.GetOxygenLevel()).Returns(0); mockExteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closed); test.RunOnce(); mockSensor.Verify(b => b.IsActive); mockExteriorDoor.Verify(b => b.OpenDoor()); //Wait For Outer Doors To Open mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closed); mockAirVent.Setup(b => b.GetOxygenLevel()).Returns(0); mockExteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Opening); test.RunOnce(); mockSensor.Verify(b => b.IsActive); mockExteriorDoor.Verify(b => b.OpenDoor()); //Complete still opens doors mockSensor.Setup(b => b.IsActive).Returns(true); mockInteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Closed); mockAirVent.Setup(b => b.GetOxygenLevel()).Returns(0); mockExteriorDoor.Setup(b => b.Status).Returns(DoorStatus.Open); test.RunOnce(); mockSensor.Verify(b => b.IsActive); mockExteriorDoor.Verify(b => b.OpenDoor()); } }
public void RocketVolleyTest() { String script = @" :setup assign global rocketGroup to 'Rockets' assign global ""fireTickInterval"" to 1 #Background Firing Loop async call ""fireLoop"" call ""stopFiring"" :toggle assign global ""firing"" to not {firing} assign global ""i"" to 0 :startFiring assign global ""firing"" to true assign global i to 0 :stopFiring tell $rocketGroup rockets to not shoot assign global ""firing"" to false :fireLoop if not {firing} replay print ""i = "" + i if {i} >= count of $rocketGroup rockets assign global i to 0 tell $rocketGroup rockets @ i to shoot tell $rocketGroup rockets to not shoot wait {fireTickInterval} ticks assign global i to i + 1 goto ""fireLoop"" "; using (var test = new ScriptTest(script)) { var mockRocket1 = new Mock <IMyUserControllableGun>(); var mockRocket2 = new Mock <IMyUserControllableGun>(); var rocket1Off = MockCalledAction(mockRocket1, "Shoot_Off"); var rocket1On = MockCalledAction(mockRocket1, "Shoot_On"); var rocket2Off = MockCalledAction(mockRocket2, "Shoot_Off"); var rocket2On = MockCalledAction(mockRocket2, "Shoot_On"); test.MockBlocksInGroup("Rockets", mockRocket1, mockRocket2); test.RunOnce(); //Setup but no firing yet rocket1Off.Verify(b => b.Apply(mockRocket1.Object)); rocket2Off.Verify(b => b.Apply(mockRocket2.Object)); rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunWithArgument("call startFiring"); //Fire Rocket 1 rocket1Off.Verify(b => b.Apply(mockRocket1.Object)); rocket2Off.Verify(b => b.Apply(mockRocket2.Object)); rocket1On.Verify(b => b.Apply(mockRocket1.Object)); rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunOnce(); //Wait 1 tick rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunOnce(); //Fire Rocket 2 rocket1Off.Verify(b => b.Apply(mockRocket1.Object)); rocket2Off.Verify(b => b.Apply(mockRocket2.Object)); rocket2On.Verify(b => b.Apply(mockRocket2.Object)); rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunOnce(); //Wait 1 tick rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); //Should restart the loop! test.RunOnce(); //Fire Rocket 1 rocket1Off.Verify(b => b.Apply(mockRocket1.Object)); rocket2Off.Verify(b => b.Apply(mockRocket2.Object)); rocket1On.Verify(b => b.Apply(mockRocket1.Object)); rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunOnce(); //Wait 1 tick rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunOnce(); //Fire Rocket 2 rocket1Off.Verify(b => b.Apply(mockRocket1.Object)); rocket2Off.Verify(b => b.Apply(mockRocket2.Object)); rocket2On.Verify(b => b.Apply(mockRocket2.Object)); rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunOnce(); //Wait 1 tick rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); test.RunWithArgument("call stopFiring"); //Fire Rocket 1 rocket1Off.Verify(b => b.Apply(mockRocket1.Object)); rocket2Off.Verify(b => b.Apply(mockRocket2.Object)); rocket1Off.VerifyNoOtherCalls(); rocket2Off.VerifyNoOtherCalls(); rocket1On.VerifyNoOtherCalls(); rocket2On.VerifyNoOtherCalls(); } }