Exemplo n.º 1
0
        public void ParallelPersistence01()
        {
            // Create and Serialize
            PersistenceParallelContext context = new PersistenceParallelContext(this.actuator);

            context.Observer = ObserverConsole.Instance;
            context.EnterInitialState();

            Assert.AreEqual(context.StateCurrent.Name, "Running");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessAContext.StateCurrent.Name, "A1");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessBContext.StateCurrent.Name, "B1");

            context.Ev12();

            Assert.AreEqual(context.StateCurrent.Name, "Running");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessAContext.StateCurrent.Name, "A2");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessBContext.StateCurrent.Name, "B2");

            string fileName = context.Name + "O1.dat";

            Serialize(context, fileName);

            // Create new , DeSerialize and check state
            PersistenceParallelContext contextSerialized = new PersistenceParallelContext(actuator);

            DeSerialize(contextSerialized, fileName);
            contextSerialized.EnterInitialState();

            Assert.AreEqual(contextSerialized.StateCurrent.Name, "Running");
            Assert.AreEqual(contextSerialized.PersistenceParallelRunningParallel.PersistenceParallelProcessAContext.StateCurrent.Name, "A2");
            Assert.AreEqual(contextSerialized.PersistenceParallelRunningParallel.PersistenceParallelProcessBContext.StateCurrent.Name, "B2");

            contextSerialized.Ev23();
            Assert.AreEqual(contextSerialized.StateCurrent.Name, "Idle");
        }
Exemplo n.º 2
0
        public void Parallel01()
        {
            // Create and Serialize
            PersistenceParallelContext context = new PersistenceParallelContext(this.actuator);

            context.Observer = ObserverConsole.Instance;
            context.EnterInitialState(); // always call  EnterInitialState for state machine which have parallel state as the first state

            Assert.AreEqual(context.StateCurrent.Name, "Running");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessAContext.StateCurrent.Name, "A1");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessBContext.StateCurrent.Name, "B1");

            context.Ev12();

            Assert.AreEqual(context.StateCurrent.Name, "Running");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessAContext.StateCurrent.Name, "A2");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessBContext.StateCurrent.Name, "B2");

            context.Ev23();
            Assert.AreEqual(context.StateCurrent.Name, "Idle");

            // Go back to Running
            context.EvRunning();
            Assert.AreEqual(context.StateCurrent.Name, "Running");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessAContext.StateCurrent.Name, "A1");
            Assert.AreEqual(context.PersistenceParallelRunningParallel.PersistenceParallelProcessBContext.StateCurrent.Name, "B1");

            //Stop
            context.EvStop();
            Assert.AreEqual(context.StateCurrent.Name, "End");

            //End state is a final state, impossible to get out of it.
            context.Ev12();
            Assert.AreEqual(context.StateCurrent.Name, "End");
            context.Ev23();
            Assert.AreEqual(context.StateCurrent.Name, "End");
            context.EvRunning();
            Assert.AreEqual(context.StateCurrent.Name, "End");
        }