public void T402_ChangeState() { TcoStateTest ts = tc._tcoObjectTest_A._tcoStateTest_A; short initState; short newState; short ccc = ts._onStateChangeCounter.Synchron; //Store the actual value of the calls of the method OnStateChange(). ts.ReadOutState(); initState = ts._myState.Synchron; //Store the previous state of the ts newState = TestHelpers.RandomNumber((short)(initState + 1), (short)(5 * (initState + 1))); //Generate new random value of the new state. Assert.AreNotEqual(initState, newState); //New state should be different as the initial state. tc.ContextOpen(); ts.TriggerChangeState(newState); //Change state of the ts to the new value newState. ts.ReadOutState(); tc.ContextClose(); Assert.AreEqual(newState, ts._myState.Synchron); //Check if the state of the ts has been changed to the newState. Assert.AreEqual(ccc + 1, ts._onStateChangeCounter.Synchron); //OnStateChange() method should be called just once, as the only one change of the state has been performed on the ts. Assert.AreEqual("My state has been change from " + initState.ToString() //Check if overiden method OnStateChange() generate expected message. + " to the new state " + newState.ToString() + ".", ts.GetMessage()); }
public void T404_Restore() { TcoStateTest ts = tc._tcoObjectTest_A._tcoStateTest_A; short newState = TestHelpers.RandomNumber(20, 100); //Generate new random value of the newState short ccc = ts._onStateChangeCounter.Synchron; //Store the actual value of the calls of the method OnStateChange(). tc.SingleCycleRun(() => { ts.TriggerChangeState(newState); //Initiate change the state of the ts to the new value newState }); ts.ReadOutState(); Assert.AreEqual(newState, ts._myState.Synchron); //Check if the state of the ts has been changed to the newState Assert.AreEqual(ccc + 1, ts._onStateChangeCounter.Synchron); //OnStateChange() method should be called just once, as the only one change of the state has been performed on the ts. ccc = ts._onStateChangeCounter.Synchron; //Store the actual value of the calls of the method OnStateChange(). tc.SingleCycleRun(() => { ts.TriggerRestore(); //By calling the Restore() method state of the ts should change to -1 }); ts.ReadOutState(); Assert.AreEqual(-1, ts._myState.Synchron); //Check if Restore() method change the state of the ts to -1. Assert.AreEqual(ccc + 1, ts._onStateChangeCounter.Synchron); //OnStateChange() method should be called just once, as the only one change of the state has been performed on the ts. }
public void T403_OnStateChange() { TcoStateTest ts = tc._tcoObjectTest_A._tcoStateTest_A; string message = TestHelpers.RandomString(20); short initState; short newState; short ccc = ts._onStateChangeCounter.Synchron; //Store the actual value of the calls of the method OnStateChange(). tc.SingleCycleRun(() => { ts.PostMessage(message); //Force test instance to post randomly generated message. }); Assert.AreEqual(message, ts.GetMessage()); //Check if the randomly generated message has been appeared in mime. ts.ReadOutState(); initState = ts._myState.Synchron; //Store the previous state of the ts newState = TestHelpers.RandomNumber((short)(initState + 1), (short)(5 * (initState + 1))); //Generate new random value of the new state. Assert.AreNotEqual(initState, newState); //New state should be different as the initial state. tc.SingleCycleRun(() => { ts.TriggerChangeState(initState); //Change state initiated to the same value as the actual state was before. From initState to initState. }); ts.ReadOutState(); Assert.AreEqual(initState, ts._myState.Synchron); //State of the ts should stay the same. Assert.AreEqual(ccc, ts._onStateChangeCounter.Synchron); //OnStateChange() method should not call, as there was no real change of the state of the ts. Assert.AreEqual(message, ts.GetMessage()); //Message should stay the same, as there was no real change of the state of the ts and therefor no OnStateChange() method should be performed. tc.SingleCycleRun(() => { ts.TriggerChangeState(newState); //Change state initiated to the different value as before. From initState to newState. }); ts.ReadOutState(); Assert.AreEqual(newState, ts._myState.Synchron); //Check if the state of the ts has been changed from initState to newState. Assert.AreEqual(ccc + 1, ts._onStateChangeCounter.Synchron); //OnStateChange() method should be called just once, as the only one change of the state has been performed on the ts. Assert.AreEqual("My state has been change from " + initState.ToString() //Check if overiden method OnStateChange() generate expected message and overwrite the message randomly generated. + " to the new state " + newState.ToString() + ".", ts.GetMessage()); }
public void T405_ChangeStateWithObjectRestore() { TcoStateTest ts = tc._tcoObjectTest_A._tcoStateTest_A; short initState; short newState; short ccc = ts._onStateChangeCounter.Synchron; //Store the actual value of the calls of the method OnStateChange(). ts.ReadOutState(); initState = ts._myState.Synchron; //Store the previous state of the ts newState = TestHelpers.RandomNumber((short)(initState + 1), (short)(5 * (initState + 1))); //Generate new random value of the new state. tc.SingleCycleRun(() => { ts.TriggerChangeState(newState); //Initiate change the state of the ts to the new value newState ts.CallTaskInstancies(); //Call instancies of the tasks that are childs of the ts ts.ReadOutState(); }); Assert.AreEqual(newState, ts._myState.Synchron); //Check if the state of the ts has been changed from initState to newState. Assert.AreEqual(ccc + 1, ts._onStateChangeCounter.Synchron); //OnStateChange() method should be called just once, as the only one change of the state has been performed on the ts. Assert.IsFalse(ts._tcoTaskTest_A._isBusy.Synchron); //Task A should be in Idle state, as it was not started Assert.IsFalse(ts._tcoTaskTest_B._isBusy.Synchron); //Task B should be in Idle state, as it was not started tc.SingleCycleRun(() => { ts.TriggerTaskInvoke(); //Calling the Invoke() methods on the both instancies of the task, should get them into the Request state ts.CallTaskInstancies(); //Following call of theirs body should get them into the Executing state. ts.ReadOutState(); }); Assert.IsTrue(ts._tcoTaskTest_A._isBusy.Synchron); //Task A should be in the Execution state. Assert.IsTrue(ts._tcoTaskTest_B._isBusy.Synchron); //Task B should be in the Execution state. initState = ts._myState.Synchron; //Store the previous state of the ts newState = TestHelpers.RandomNumber((short)(initState + 1), (short)(5 * (initState + 1))); //Generate new random value of the new state. ccc = ts._onStateChangeCounter.Synchron; //Store the actual value of the calls of the method OnStateChange(). tc.SingleCycleRun(() => { ts.TriggerChangeStateWithObjectRestore(newState); //Changing state of the ts with manual object restore using fluent syntax: ts.ChangeState(newState).ObjectRestore(TaskA).ObjectRestore(TaskB); ts.CallTaskInstancies(); ts.ReadOutState(); }); Assert.AreEqual(newState, ts._myState.Synchron); //Check if the state of the ts has been changed to the newState Assert.AreEqual(ccc + 1, ts._onStateChangeCounter.Synchron); //OnStateChange() method should be called just once, as the only one change of the state has been performed on the ts. Assert.IsFalse(ts._tcoTaskTest_A._isBusy.Synchron); //Task A should be in Idle state, as it was restored. Assert.IsFalse(ts._tcoTaskTest_B._isBusy.Synchron); //Task B should be in Idle state, as it was restored. }