Пример #1
0
        public void ShouldExecuteEventActionsWhenLoadedFromDSL()
        {
            var stateMachine = new StateMachine();

            var builder = _factory.Create <StateMachineBuilder>("EventActionTestMachine.boo");

            builder.BuildStateMachine(stateMachine);

            var context = new StateMachineContext(stateMachine, null, null);

            context.Start();

            TestStateMachineTask.Clear();

            context.HandleEvent(1);

            Assert.That(TestStateMachineTask.EventHistory.Count, Is.EqualTo(1));

            context.HandleEvent(2);

            Assert.That(TestStateMachineTask.EventHistory.Count, Is.EqualTo(2));


            context.HandleEvent(1);

            Assert.That(TestStateMachineTask.EventHistory.Count, Is.EqualTo(3));
        }
Пример #2
0
        public void TransitionActionTest()
        {
            var stateMachine = new StateMachine();

            stateMachine.RegisterTaskAssembly(GetType().Assembly);

            stateMachine.AddStateInitializationAction("TestyTheTest");

            IStateMachineEvent e1 = stateMachine.AddNewEvent("Event1");
            IStateMachineEvent e2 = stateMachine.AddNewEvent("Event2");


            var initial = stateMachine.AddNewState("Initial") as StateMachineState;
            var first   = stateMachine.AddNewState("First") as StateMachineState;

            initial.AddNewTransition(e1, first);

            first.AddNewTransition(e1, initial);
            first.AddNewTransition(e2, first);

            first.AddStateFinalizationAction("TestyTheTest::AlternateMethod");

            var context = new StateMachineContext(stateMachine, null, null);

            context.Start();

            TestStateMachineTask.Clear();

            context.HandleEvent(e1);

            Assert.That(TestStateMachineTask.PhaseHistory.Count, Is.EqualTo(1));

            context.HandleEvent(e2);

            Assert.That(TestStateMachineTask.PhaseHistory.Count, Is.EqualTo(3));

            //Global init, Local Finalize, Global init
            Assert.That(TestStateMachineTask.PhaseHistory[0], Is.EqualTo(StateTransitionPhase.StateInitialization));
            Assert.That(TestStateMachineTask.PhaseHistory[1], Is.EqualTo(StateTransitionPhase.StateFinalization));
            Assert.That(TestStateMachineTask.PhaseHistory[2], Is.EqualTo(StateTransitionPhase.StateInitialization));

            //first inits, first finalizes, first inits
            Assert.That(TestStateMachineTask.StateHistory[0], Is.SameAs(first));
            Assert.That(TestStateMachineTask.StateHistory[1], Is.SameAs(first));
            Assert.That(TestStateMachineTask.StateHistory[1], Is.SameAs(first));

            context.HandleEvent(e1);

            //first finalizes, initial inits
            Assert.That(TestStateMachineTask.StateHistory[3], Is.SameAs(first));
            Assert.That(TestStateMachineTask.StateHistory[4], Is.SameAs(initial));

            Assert.That(TestStateMachineTask.PhaseHistory[3], Is.EqualTo(StateTransitionPhase.StateFinalization));
            Assert.That(TestStateMachineTask.PhaseHistory[4], Is.EqualTo(StateTransitionPhase.StateInitialization));
        }
Пример #3
0
        public void ShouldExecuteAssignedActionWhenEventIsReceived()
        {
            var stateMachine = new StateMachine();

            stateMachine.RegisterTaskAssembly(GetType().Assembly);

            IStateMachineEvent e1 = stateMachine.AddNewEvent("Event1");//.Action("TestyTheTest");
            IStateMachineEvent e2 = stateMachine.AddNewEvent("Event2");

            stateMachine.AddNewEventAction("TestyTheTest", e1);

            var initial = stateMachine.AddNewState("Initial") as StateMachineState;
            var first   = stateMachine.AddNewState("First") as StateMachineState;

            initial.AddNewEventAction("TestyTheTest", e1);


            initial.AddNewTransition(e1, first);

            first.AddNewTransition(e1, initial);
            first.AddNewTransition(e2, first);

            var context = new StateMachineContext(stateMachine, null, null);

            context.Start();

            TestStateMachineTask.Clear();

            context.HandleEvent(e1);

            Assert.That(TestStateMachineTask.PhaseHistory.Count, Is.EqualTo(2));

            context.HandleEvent(e2);

            Assert.That(TestStateMachineTask.PhaseHistory.Count, Is.EqualTo(2));

            Assert.That(TestStateMachineTask.EventHistory[0], Is.SameAs(e1));

            context.HandleEvent(e1);

            Assert.That(TestStateMachineTask.EventHistory.Count, Is.EqualTo(3));
            Assert.That(TestStateMachineTask.EventHistory[1], Is.SameAs(e1));
        }
Пример #4
0
        public void TransitionActionTestFromDSL()
        {
            var stateMachine = new StateMachine();

            var builder = _factory.Create <StateMachineBuilder>("SimpleStateMachine.boo");

            builder.BuildStateMachine(stateMachine);

            var context = new StateMachineContext(stateMachine, null, null);

            context.Start();

            TestStateMachineTask.Clear();

            context.HandleEvent(1);

            Assert.That(TestStateMachineTask.PhaseHistory.Count, Is.EqualTo(1));

            context.HandleEvent(2);

            Assert.That(TestStateMachineTask.PhaseHistory.Count, Is.EqualTo(3));

            //Global init, Local Finalize, Global init
            Assert.That(TestStateMachineTask.PhaseHistory[0], Is.EqualTo(StateTransitionPhase.StateInitialization));
            Assert.That(TestStateMachineTask.PhaseHistory[1], Is.EqualTo(StateTransitionPhase.StateFinalization));
            Assert.That(TestStateMachineTask.PhaseHistory[2], Is.EqualTo(StateTransitionPhase.StateInitialization));

            //first inits, first finalizes, first inits
            Assert.That(TestStateMachineTask.StateHistory[0], Is.SameAs(stateMachine.States[1]));
            Assert.That(TestStateMachineTask.StateHistory[1], Is.SameAs(stateMachine.States[1]));
            Assert.That(TestStateMachineTask.StateHistory[1], Is.SameAs(stateMachine.States[1]));

            context.HandleEvent(1);

            //first finalizes, initial inits
            Assert.That(TestStateMachineTask.StateHistory[3], Is.SameAs(stateMachine.States[1]));
            Assert.That(TestStateMachineTask.StateHistory[4], Is.SameAs(stateMachine.States[0]));

            Assert.That(TestStateMachineTask.PhaseHistory[3], Is.EqualTo(StateTransitionPhase.StateFinalization));
            Assert.That(TestStateMachineTask.PhaseHistory[4], Is.EqualTo(StateTransitionPhase.StateInitialization));
        }