Пример #1
0
        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());
        }
Пример #2
0
        public void T400_IdentitiesTest()
        {
            TcoObjectTest to = tc._tcoObjectTest_A;                                                     //to is the child of the tc
            TcoStateTest  ts = to._tcoStateTest_A;                                                      //ts is the child of the to and grandchild of the tc
            TcoTaskTest   tt = ts._tcoTaskTest_A;                                                       //tt is the child of the ts and great-grandchild of the tc

            tc._callMyPlcInstance.Synchron = true;                                                      //Switch on the cyclical execution of the tc instance

            Thread.Sleep(300);                                                                          //Time of the cyclical execution of the test instance
            tc._callMyPlcInstance.Synchron = false;                                                     //Switch off the cyclical execution of the tc instance

            tc.ReadOutCycleCounters();                                                                  //Read out actual cycle counters values into the test instance

            Assert.Greater(tc._startCycles.Synchron, 0);                                                //StartCycleCounter should be greather than zero as test instance was running at least 300ms.
            Assert.Greater(tc._endCycles.Synchron, 0);                                                  //EndCycleCounter should be greather than zero as test instance was running at least 300ms.

            to.ReadOutIdentities();                                                                     //Readout identities into the test instance
            ts.ReadOutIdentities();                                                                     //Readout identities into the test instance
            tt.ReadOutIdentities();                                                                     //Readout identities into the test instance

            Assert.AreEqual(tc._myIdentity.Synchron, to._myContextIdentity.Synchron);                   //Identity of the child's context (to) is the same as the identity of the parent(tc)
            Assert.AreEqual(tc._myIdentity.Synchron, ts._myContextIdentity.Synchron);                   //Identity of the grandchild's context (ts) is the same as the identity of the grandparent(tc)
            Assert.AreEqual(tc._myIdentity.Synchron, tt._myContextIdentity.Synchron);                   //Identity of the great-grandchild's context (tt) is the same as the identity of the great-grandparent(tc)

            Assert.AreNotEqual(tc._myIdentity.Synchron, to._myIdentity.Synchron);                       //Identity of the child(to) is different than the identity of its parent(tc), as they are both unique objects.
            Assert.AreNotEqual(tc._myIdentity.Synchron, ts._myIdentity.Synchron);                       //Identity of the grandchild(ts) is different than the identity of its grandparent(tc), as they are both unique objects.
            Assert.AreNotEqual(tc._myIdentity.Synchron, tt._myIdentity.Synchron);                       //Identity of the great-grandchild(tt) is different than the identity of its great-grandparent(tc), as they are both unique objects.

            Assert.AreNotEqual(to._myIdentity.Synchron, ts._myIdentity.Synchron);                       //Identity of the grandchild(ts) is different than the identity of its parent(to), as they are both unique objects.
            Assert.AreNotEqual(to._myIdentity.Synchron, tt._myIdentity.Synchron);                       //Identity of the great-grandchild(tt) is different than the identity of its grandparent(to), as they are both unique objects.
        }
Пример #3
0
        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.
        }
Пример #4
0
        public void T401_StateMessage()
        {
            TcoStateTest ts      = tc._tcoObjectTest_A._tcoStateTest_A;
            string       message = TestHelpers.RandomString(20);

            tc.ContextOpen();
            ts.PostMessage(message);                                                                    //Force the error message to the task instence
            tc.ContextClose();

            Assert.AreEqual(message, ts.GetMessage());                                                  //Check if message apears in the mime.
        }
Пример #5
0
        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.
        }
Пример #6
0
        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());
        }