Exemple #1
0
        public void Signal_GivenTriggeredTransition_TransitionNotTraversed()
        {
            var uut     = StateMachineFactory.Create <DummyState>("Test StateMachine", _logger);
            var harness = new StateMachineTestHarness <DummyState>(uut, DummyState.One.ToString());

            TestBuilder.BuildOneWayMachineWithTriggers(harness.Machine, harness);

            uut.CompleteEdit();
            Assert.AreEqual(DummyState.One, uut.CurrentState);

            bool signalResult = uut.Signal(new DataWaypoint(this, "Test method"));

            Assert.IsFalse(signalResult, "A transition was traversed but should not have been.");
            Assert.AreEqual(DummyState.One, uut.CurrentState);
        }
Exemple #2
0
        public void Signal_GivenPassiveTransitionAndAutoAdvanceOn_MultipleTransitionTraversed()
        {
            var uut     = StateMachineFactory.Create <DummyState>("Test StateMachine", _logger);
            var harness = new StateMachineTestHarness <DummyState>(uut, DummyState.One.ToString());

            TestBuilder.BuildOneWayPassiveMachine(harness.Machine);

            uut.AutoAdvance = true;
            uut.CompleteEdit();
            Assert.AreEqual(DummyState.One, uut.CurrentState);

            bool signalResult = uut.Signal(new DataWaypoint(this, "Test method"));

            Assert.IsTrue(signalResult, "Failed to signal the machine under test.");
            Assert.AreEqual(DummyState.Three, uut.CurrentState);
        }
        public static void BuildCircularMachineWithTriggers <TState>(StateMachine <TState> machine, StateMachineTestHarness <TState> triggerSource) where TState : struct
        {
            BuildOneWayMachineWithTriggers(machine, triggerSource);

            // Transition from the last state back to the first.
            int last       = machine.States.Count - 1;
            var trigger    = new Trigger <StateMachineTestHarness <TState>, EventArgs>(triggerSource, "TestTrigger", machine.TriggerScheduler, machine.Logger);
            var transition = machine.CreateTransition(machine.States[last].Name, machine.States[0].Name);

            transition.Edit();
            transition.AddTrigger(trigger);

            //transition.Succeeded += Transition_Succeeded;
            //transition.Failed += Transition_Failed;
        }
        public static void BuildOneWayMachineWithTriggers <TState>(StateMachine <TState> machine, StateMachineTestHarness <TState> triggerSource) where TState : struct
        {
            for (int i = 0; i < machine.States.Count; i++)
            {
                if (i + 1 < machine.States.Count)
                {
                    var trigger    = new Trigger <StateMachineTestHarness <TState>, EventArgs>(triggerSource, "TestTrigger", machine.TriggerScheduler, machine.Logger);
                    var transition = machine.CreateTransition(machine.States[i].Name, machine.States[i + 1].Name);
                    transition.Edit();
                    transition.AddTrigger(trigger);

                    //transition.Succeeded += Transition_Succeeded;
                    //transition.Failed += Transition_Failed;
                }
            }
        }