public void OnThreeAdvancesShouldChangeActiveRecursiveSubStepAndReturnThirdInteraction() { // Arrange List <Step> hugSteps = new List <Step>(); RecursiveStep hugSequentialStep = new RecursiveStep(Standard.Mandatory, "Hug.", hugSteps); hugSequentialStep.AddSubStep(_grabHugStep); hugSequentialStep.AddSubStep(_takeKeyStep); List <Step> doorSteps = new List <Step>(); RecursiveStep doorSequentialStep = new RecursiveStep(Standard.Mandatory, "Door", doorSteps); doorSequentialStep.AddSubStep(_insertKeyStep); doorSequentialStep.AddSubStep(_openDoorStep); List <Step> multiNivelSequentialSteps = new List <Step>(); RecursiveStep multiNivelSequentialStep = new RecursiveStep(Standard.Mandatory, "Unlock Door", multiNivelSequentialSteps); multiNivelSequentialStep.AddSubStep(hugSequentialStep); multiNivelSequentialStep.AddSubStep(doorSequentialStep); // Act multiNivelSequentialStep.AdvanceStep(DateTime.Now); multiNivelSequentialStep.AdvanceStep(DateTime.Now); LeafStep third = multiNivelSequentialStep.AdvanceStep(DateTime.Now); // Assert Assert.AreEqual(true, hugSequentialStep.Completed); Assert.AreEqual(false, hugSequentialStep.Active); Assert.AreEqual(false, doorSequentialStep.Completed); Assert.AreEqual(true, doorSequentialStep.Active); Assert.AreEqual(_insertKeyStep.Interaction, third.Interaction); Assert.AreEqual(doorSequentialStep, multiNivelSequentialStep.CurrentSubStep); }
public void OnTwoAdvancesMultinivelSequentialStepsShouldBeNonCompletedActiveAndReturnSecondInteraction() { // Arrange List <Step> hugSteps = new List <Step>(); RecursiveStep hugSequentialStep = new RecursiveStep(Standard.Mandatory, "Hug.", hugSteps); hugSequentialStep.AddSubStep(_grabHugStep); hugSequentialStep.AddSubStep(_takeKeyStep); List <Step> doorSteps = new List <Step>(); RecursiveStep doorSequentialStep = new RecursiveStep(Standard.Mandatory, "Door", doorSteps); doorSequentialStep.AddSubStep(_insertKeyStep); doorSequentialStep.AddSubStep(_openDoorStep); List <Step> multiNivelSequentialSteps = new List <Step>(); RecursiveStep multiNivelSequentialStep = new RecursiveStep(Standard.Mandatory, "Unlock Door", multiNivelSequentialSteps); multiNivelSequentialStep.AddSubStep(hugSequentialStep); multiNivelSequentialStep.AddSubStep(doorSequentialStep); // Act multiNivelSequentialStep.AdvanceStep(DateTime.Now); LeafStep second = multiNivelSequentialStep.AdvanceStep(DateTime.Now); // Assert Assert.AreEqual(false, multiNivelSequentialStep.Completed); Assert.AreEqual(true, multiNivelSequentialStep.Active); Assert.AreEqual(_takeKeyStep.Interaction, second.Interaction); }
public Setup() { var keyAssetMock = new Asset("key", "key.jpg", "key.fbx"); var hugAssetMock = new Asset("hug", "hug.jpg", "hug.fbx"); var doorssetMock = new Asset("door", "door.jpg", "door.fbx"); Description takeKeyDescription = new Description("Take the Key."); Duration takeKeyExpected = new Duration(1000); Duration takeKeyLimit = new Duration(2000); _keyInteraction = new Interaction(Act.Grab, takeKeyDescription, takeKeyExpected, takeKeyLimit, keyAssetMock); _takeKeyStep = new LeafStep(Standard.Mandatory, "Taking Key", _keyInteraction); Description insertKeyDescription = new Description("Insert key into door."); Duration insertKeyExpected = new Duration(1000); Duration insertKeyLimit = new Duration(2000); _keyholeInteraction = new Interaction(Act.Grab, insertKeyDescription, insertKeyExpected, insertKeyLimit, keyAssetMock, doorssetMock); _insertKeyStep = new LeafStep(Standard.Mandatory, "Insert key.", _keyholeInteraction); Description openDoorDescription = new Description("Open door."); Duration openDoorExpected = new Duration(1000); Duration openDoorLimit = new Duration(2000); _doorInteraction = new Interaction(Act.Grab, openDoorDescription, openDoorExpected, openDoorLimit, doorssetMock); _openDoorStep = new LeafStep(Standard.Mandatory, "Insert key.", _doorInteraction); Description grabHugDescription = new Description("Grab HUg."); Duration grabHugExpected = new Duration(1000); Duration grabHugLimit = new Duration(2000); _grabHugInteraction = new Interaction(Act.Grab, grabHugDescription, grabHugExpected, grabHugLimit, hugAssetMock); _grabHugStep = new LeafStep(Standard.Mandatory, "Insert key.", _grabHugInteraction); List <Step> hugSteps = new List <Step>(); RecursiveStep hugSequentialStep = new RecursiveStep(Standard.Mandatory, "Hug.", hugSteps); hugSequentialStep.AddSubStep(_grabHugStep); hugSequentialStep.AddSubStep(_takeKeyStep); List <Step> doorSteps = new List <Step>(); RecursiveStep doorSequentialStep = new RecursiveStep(Standard.Mandatory, "Door", doorSteps); doorSequentialStep.AddSubStep(_insertKeyStep); doorSequentialStep.AddSubStep(_openDoorStep); List <Step> multiNivelSequentialSteps = new List <Step>(); _MultinivelStep = new RecursiveStep(Standard.Mandatory, "Unlock Door", multiNivelSequentialSteps); _MultinivelStep.AddSubStep(hugSequentialStep); _MultinivelStep.AddSubStep(doorSequentialStep); }
public void OnInitialStateExecutionAndLimitTimeShouldBeCorrectCalculated() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); sequentialStep.UpdateDuration(); // Assert Assert.AreEqual(3000, sequentialStep.ExpectedDuration.Seconds); Assert.AreEqual(6000, sequentialStep.LimitDuration.Seconds); }
public void OnInitialStateShouldBeNonActiveAndNonCompleted() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); // Assert Assert.AreEqual(false, sequentialStep.Active); Assert.AreEqual(false, sequentialStep.Completed); }
public void OnActivationShouldReturnFirstInteractionBeActiveAndNonCompleted() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); DateTime firstTime = DateTime.Now; // Act Interaction first = sequentialStep.AdvanceStep(firstTime).Interaction; // Assert Assert.AreEqual(_keyInteraction, first); Assert.AreEqual(false, sequentialStep.Completed); Assert.AreEqual(true, sequentialStep.Active); }
public void OnCompletionAndCalculationAllTimesShouldBeCorrect() { // Arrange List <Step> hugSteps = new List <Step>(); RecursiveStep hugSequentialStep = new RecursiveStep(Standard.Mandatory, "Hug.", hugSteps); hugSequentialStep.AddSubStep(_grabHugStep); hugSequentialStep.AddSubStep(_takeKeyStep); List <Step> doorSteps = new List <Step>(); RecursiveStep doorSequentialStep = new RecursiveStep(Standard.Mandatory, "Door", doorSteps); doorSequentialStep.AddSubStep(_insertKeyStep); doorSequentialStep.AddSubStep(_openDoorStep); List <Step> multiNivelSequentialSteps = new List <Step>(); RecursiveStep multiNivelSequentialStep = new RecursiveStep(Standard.Mandatory, "Unlock Door", multiNivelSequentialSteps); multiNivelSequentialStep.AddSubStep(hugSequentialStep); multiNivelSequentialStep.AddSubStep(doorSequentialStep); DateTime firstTime = DateTime.Now; DateTime secondTime = DateTime.Now; DateTime thirdTime = DateTime.Now; DateTime fourthTime = DateTime.Now; DateTime fifthTime = DateTime.Now; // Act multiNivelSequentialStep.UpdateDuration(); multiNivelSequentialStep.AdvanceStep(firstTime); multiNivelSequentialStep.AdvanceStep(secondTime); multiNivelSequentialStep.AdvanceStep(thirdTime); System.Threading.Thread.Sleep(2000); multiNivelSequentialStep.AdvanceStep(fourthTime); multiNivelSequentialStep.AdvanceStep(fifthTime); // Assert Assert.AreEqual(4000, multiNivelSequentialStep.ExpectedDuration.Seconds); Assert.AreEqual(8000, multiNivelSequentialStep.LimitDuration.Seconds); var timeOffset = fifthTime.Subtract(firstTime).TotalSeconds; Assert.AreEqual((long)timeOffset, (long)multiNivelSequentialStep.ExecutionTime.Seconds); }
public void OnSecondAdvanceShouoldReturnSecondInteractionAndBeActiveAndNonCompelted() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); DateTime firstTime = DateTime.Now; DateTime secondTime = DateTime.Now; // Act sequentialStep.AdvanceStep(firstTime); Interaction second = sequentialStep.AdvanceStep(secondTime).Interaction; // Assert Assert.AreEqual(_keyholeInteraction, second); Assert.AreEqual(false, sequentialStep.Completed); Assert.AreEqual(true, sequentialStep.Active); }
public void OnCompletionExecutionTimeShouldBeCalculated() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); DateTime firstTime = DateTime.Now; DateTime secondTime = DateTime.Now; DateTime thirdTime = DateTime.Now; DateTime fourthTime = DateTime.Now; // Act sequentialStep.AdvanceStep(firstTime); sequentialStep.AdvanceStep(secondTime); sequentialStep.AdvanceStep(thirdTime); sequentialStep.AdvanceStep(fourthTime); // Assert Assert.AreEqual(fourthTime.Subtract(firstTime).TotalSeconds, sequentialStep.ExecutionTime.Seconds, 0.1); }
public void OnCompletedAdvancingStepShouldFail() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); DateTime firstTime = DateTime.Now; DateTime secondTime = DateTime.Now; DateTime thirdTime = DateTime.Now; DateTime fourthTime = DateTime.Now; DateTime fifthTime = DateTime.Now; // Act sequentialStep.AdvanceStep(firstTime); //starts sequentialStep.AdvanceStep(secondTime); //finishes first and starts second sequentialStep.AdvanceStep(thirdTime); //finishes second and starts third sequentialStep.AdvanceStep(fourthTime); //finishes third and completes sequentialStep.AdvanceStep(fifthTime); //exception }
public void OnCompletionShouldReturnNullAsInteractionBeCompletedAndNonActive() { // Arrange List <Step> steps = new List <Step>(); RecursiveStep sequentialStep = new RecursiveStep(Standard.Mandatory, "Door", steps); sequentialStep.AddSubStep(_takeKeyStep); sequentialStep.AddSubStep(_insertKeyStep); sequentialStep.AddSubStep(_openDoorStep); DateTime firstTime = DateTime.Now; DateTime secondTime = DateTime.Now; DateTime thirdTime = DateTime.Now; DateTime fourthTime = DateTime.Now; // Act sequentialStep.AdvanceStep(firstTime); sequentialStep.AdvanceStep(secondTime); sequentialStep.AdvanceStep(thirdTime); sequentialStep.AdvanceStep(fourthTime); // Assert Assert.AreEqual(null, sequentialStep.CurrentSubStep); Assert.AreEqual(true, sequentialStep.Completed); Assert.AreEqual(false, sequentialStep.Active); }