public IEnumerator CompleteWhenTouched() { // Setup object with mocked grabbed property and activate GameObject obj = new GameObject("T1"); TouchablePropertyMock mockedProperty = obj.AddComponent <TouchablePropertyMock>(); yield return(new WaitForFixedUpdate()); TouchedCondition condition = new TouchedCondition(mockedProperty); condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // When the object is touched mockedProperty.SetTouched(true); yield return(null); condition.Update(); // Assert that condition is now completed Assert.IsTrue(condition.IsCompleted); }
public IEnumerator ConditionNotCompleted() { // Setup object with mocked grabbed property and activate GameObject obj = new GameObject("T1"); TouchablePropertyMock mockedProperty = obj.AddComponent <TouchablePropertyMock>(); TouchedCondition condition = new TouchedCondition(mockedProperty); condition.LifeCycle.Activate(); float startTime = Time.time; while (Time.time < startTime + 0.1f) { yield return(null); condition.Update(); } // Assert after doing nothing the condition is not completed. Assert.IsFalse(condition.IsCompleted); }
public IEnumerator FastForwardDoesNotCompleteCondition() { // Given a touched condition, GameObject obj = new GameObject("T1"); TouchablePropertyMock mockedProperty = obj.AddComponent <TouchablePropertyMock>(); yield return(new WaitForFixedUpdate()); TouchedCondition condition = new TouchedCondition(mockedProperty); bool wasTouched = false; bool wasUntouched = false; mockedProperty.Touched += (sender, args) => { wasTouched = true; mockedProperty.Untouched += (unsender, unargs) => wasUntouched = true; }; // When you activate it, condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } // When you fast-forward it condition.LifeCycle.MarkToFastForward(); // Then nothing happens. Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage); Assert.IsFalse(condition.IsCompleted); Assert.IsFalse(wasUntouched); Assert.IsFalse(wasTouched); }
public IEnumerator CompleteWhenItIsDoneOnStart() { // Setup object with mocked grabbed property and activate GameObject obj = new GameObject("T1"); TouchablePropertyMock mockedProperty = obj.AddComponent <TouchablePropertyMock>(); mockedProperty.SetTouched(true); yield return(new WaitForFixedUpdate()); TouchedCondition condition = new TouchedCondition(mockedProperty); condition.LifeCycle.Activate(); while (condition.IsCompleted == false) { yield return(null); condition.Update(); } // Assert that condition is now completed due IsGrabbed being true Assert.IsTrue(condition.IsCompleted); }
public IEnumerator AutoCompleteActive() { // Given a touched condition, GameObject obj = new GameObject("T1"); TouchablePropertyMock mockedProperty = obj.AddComponent <TouchablePropertyMock>(); yield return(new WaitForFixedUpdate()); TouchedCondition condition = new TouchedCondition(mockedProperty); bool wasTouched = false; bool wasUntouched = false; mockedProperty.Touched += (sender, args) => { wasTouched = true; mockedProperty.Untouched += (unsender, unargs) => wasUntouched = true; }; // When you activate and autocomplete it, condition.LifeCycle.Activate(); while (condition.LifeCycle.Stage != Stage.Active) { yield return(null); condition.Update(); } condition.Autocomplete(); // Then it is completed. Assert.AreEqual(Stage.Active, condition.LifeCycle.Stage); Assert.IsTrue(wasTouched); Assert.IsTrue(wasUntouched); }