public MainSs(MyDataClass dataClass)
            : base(MyStateID.Main, dataClass)
        {
            MySuperState notStarted = new NotStartedSs(this, dataClass);
            MySuperState recovery = new RecoverySs(this, dataClass);

            this.AddSubState(notStarted);
            this.AddSubState(recovery);

            // Register Started state transitions
            //notStarted.RegisterOnEventTransition(MyEventType.Start, new SpStateTransition(SpStateTransitionType.NextState, recovery, null));
            //notStarted.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            // Register OnResult so that the Superstate can handle its state's ExitState transitions
            //            notStarted.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, null));

            // REGISTER A PROPER RETURN MSG
            notStarted.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, new MyTickMsg()));

            //// Register active state transitions
            //active.RegisterOnEventTransition(MyEventType.Stop, new SpStateTransition(SpStateTransitionType.NextState, idle, null));
            //active.RegisterOnEventTransition(MyEventType.Abort, new SpStateTransition(SpStateTransitionType.ExitState, null, null));

            //// Only on events registered.  On abor goes exit state

            //this.RegisterOnResultTransition(new SpEnumToInt(MyEventType.Abort), new SpStateTransition(SpStateTransitionType.NextState, recovery, new MyTickMsg()));

            this.SetEntryState(notStarted);
        }
        public void TestDeferedTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {

                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpEventListner listner;
                SpStateMachineEngine engine = this.GetEngine(out listner, dataClass, notStartedSs);

                engine.Start();
                Thread.Sleep(600);
                Assert.AreEqual("NotStarted.Idle", notStartedSs.FullName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyEventType.Start));
                Thread.Sleep(700);
                Assert.AreEqual("NotStarted.Active", notStartedSs.FullName);

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyEventType.Abort));
                Thread.Sleep(700);
                Assert.AreEqual("NotStarted.Idle", notStartedSs.FullName);

                Thread.Sleep(200);
                engine.Stop();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");
            });
        }
        public void TestDeferedTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {

                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass();
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpStateMachine sm = new MyStateMachine(dataClass, notStartedSs);

                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");
                //this.TickAndValidateState(new MyTickMsg(), sm, "NotStarted.Idle");

                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Start), sm, "NotStarted.Active");
                this.TickAndValidateState(this.GetMsg(MyEventType.Abort), sm, "NotStarted.Idle");
                this.TickAndValidateState(this.GetMsg(MyEventType.Tick), sm, "NotStarted.Idle");
            });
        }
        public void TestEventTransitionsInSuperState()
        {
            TestHelpers.CatchUnexpected(() => {

                // Setting flip count will cause back and fourth between active and idle
                MyDataClass dataClass = new MyDataClass() { FlipStateCount = 2 };
                MySuperState notStartedSs = new NotStartedSs(null, dataClass);
                ISpEventListner listner;
                SpStateMachineEngine engine = this.GetEngine(out listner, dataClass, notStartedSs);

                engine.Start();
                Thread.Sleep(2000);

                engine.Stop();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");
            });
        }