public void _0_DisposeObject_Success()
        {
            ISpEventListner listner = MockRepository.GenerateMock<ISpEventListner>();
            ISpEventStore st = MockRepository.GenerateMock<ISpEventStore>();
            ISpBehaviorOnEvent be = MockRepository.GenerateMock<ISpBehaviorOnEvent>();
            ISpStateMachine sm = MockRepository.GenerateMock<ISpStateMachine>();
            ISpPeriodicTimer tm = MockRepository.GenerateMock<ISpPeriodicTimer>();

            TestHelpers.CatchUnexpected(() => {
                SpStateMachineEngine engine = new SpStateMachineEngine(listner, st, be, sm, tm);
                engine.Dispose();
            });
        }
        public void _0_Dispose_MultiDisposeSafe()
        {
            ISpEventListner listner = MockRepository.GenerateMock<ISpEventListner>();
            listner.Expect((o) => o.Dispose()).Throw(new Exception("Listner exception"));

            ISpEventStore st = MockRepository.GenerateMock<ISpEventStore>();
            ISpBehaviorOnEvent be = MockRepository.GenerateMock<ISpBehaviorOnEvent>();
            ISpStateMachine sm = MockRepository.GenerateMock<ISpStateMachine>();
            ISpPeriodicTimer tm = MockRepository.GenerateMock<ISpPeriodicTimer>();

            TestHelpers.CatchUnexpected(() => {
                SpStateMachineEngine engine = new SpStateMachineEngine(listner, st, be, sm, tm);
                Console.WriteLine("Test: Disposing");
                engine.Dispose();
                engine.Dispose();
                engine.Dispose();
                engine.Dispose();
                engine.Dispose();
                Thread.Sleep(500); // Nothing stopping the thead internaly with mocks
                Console.WriteLine("Test: Finished Disposing");
            });

            this.logReader.Validate(50060, "SpStateMachineEngine", "DisposeObject", "Error Disposing Object:msgListner");
        }
        public void _50050_SpStateMachineEngine_nullListner()
        {
            ISpEventListner listner = MockRepository.GenerateMock<ISpEventListner>();
            ISpEventStore st = MockRepository.GenerateMock<ISpEventStore>();
            ISpBehaviorOnEvent be = MockRepository.GenerateMock<ISpBehaviorOnEvent>();
            ISpStateMachine sm = MockRepository.GenerateMock<ISpStateMachine>();
            ISpPeriodicTimer tm = MockRepository.GenerateMock<ISpPeriodicTimer>();

            TestHelpers.CatchExpected(50050, "SpStateMachineEngine", ".ctor", "Null msgListner Argument", () => {
                SpStateMachineEngine engine = new SpStateMachineEngine(null, st, be, sm, tm);
                engine.Dispose();
            });

            //this.logReader.Validate(50060, "SpStateMachineEngine", "DisposeObject", "Error Disposing Object:msgListner");
        }
        public void _50058_DriverThreadUnexpectedError()
        {
            ISpEventListner listner = MockRepository.GenerateMock<ISpEventListner>();
            listner.Expect((o) => o.Dispose()).Throw(new Exception("Listner exception"));

            ISpEventStore st = MockRepository.GenerateMock<ISpEventStore>();
            ISpBehaviorOnEvent be = MockRepository.GenerateMock<ISpBehaviorOnEvent>();
            be.Expect((o) => o.WaitOnEvent()).Throw(new Exception("Behavior WaitOn Exception"));

            ISpStateMachine sm = MockRepository.GenerateMock<ISpStateMachine>();
            ISpPeriodicTimer tm = MockRepository.GenerateMock<ISpPeriodicTimer>();

            TestHelpers.CatchUnexpected(() => {
                SpStateMachineEngine engine = new SpStateMachineEngine(listner, st, be, sm, tm);
                Console.WriteLine("Test: Disposing");
                engine.Dispose();
                Thread.Sleep(500); // Nothing stopping the thead internaly with mocks
            });

            this.logReader.Validate(50058, "SpStateMachineEngine", "DriverThread", "Unexpected Error");
        }
        public void _50057_StopDisposed()
        {
            ISpEventListner listner = MockRepository.GenerateMock<ISpEventListner>();
            listner.Expect((o) => o.Dispose()).Throw(new Exception("Listner exception"));

            ISpEventStore st = MockRepository.GenerateMock<ISpEventStore>();
            ISpBehaviorOnEvent be = MockRepository.GenerateMock<ISpBehaviorOnEvent>();
            ISpStateMachine sm = MockRepository.GenerateMock<ISpStateMachine>();
            ISpPeriodicTimer tm = MockRepository.GenerateMock<ISpPeriodicTimer>();

            TestHelpers.CatchExpected(50057, "SpStateMachineEngine", "Stop", "Attempting to use Disposed Object", () => {
                SpStateMachineEngine engine = new SpStateMachineEngine(listner, st, be, sm, tm);
                Console.WriteLine("Test: Disposing");
                engine.Dispose();
                Thread.Sleep(500); // Nothing stopping the thead internaly with mocks
                engine.Stop();

            });
        }
        public void _50054_SpStateMachineEngine_nullTimer()
        {
            ISpEventListner listner = MockRepository.GenerateMock<ISpEventListner>();
            ISpEventStore st = MockRepository.GenerateMock<ISpEventStore>();
            ISpBehaviorOnEvent be = MockRepository.GenerateMock<ISpBehaviorOnEvent>();
            ISpStateMachine sm = MockRepository.GenerateMock<ISpStateMachine>();
            ISpPeriodicTimer tm = MockRepository.GenerateMock<ISpPeriodicTimer>();

            TestHelpers.CatchExpected(50054, "SpStateMachineEngine", ".ctor", "Null timer Argument", () => {
                SpStateMachineEngine engine = new SpStateMachineEngine(listner, st, be, sm, null);
                engine.Dispose();
            });
        }
        public void TestInitialGenericSpState()
        {
            TestHelpers.CatchUnexpected(() => {

                MyDataClass dataClass = new MyDataClass();
                // This would normally be the main superstate which includes all other states cascading within it's and it's children's constructors

                MyState sParent = new MyState(MyStateID.NotStarted, dataClass);
                MyState s = new MyState(sParent, MyStateID.WaitingForUserInput, dataClass);
                MyState s2 = new MyState(sParent, MyStateID.Active, dataClass);

                Console.WriteLine("SuperState sParent name:{0}", sParent.FullName);
                Console.WriteLine("State s name:{0}", s.FullName);
                Console.WriteLine("State s2 name:{0}", s2.FullName);

                s.RegisterOnEventTransition(new SpEnumToInt(MyEventType.Stop), new SpStateTransition(SpStateTransitionType.NextState, s2, null));

                ISpStateMachine sm = new MyStateMachine(dataClass, s);
                ISpEventStore store = new SimpleDequeEventStore(new MyTickMsg());
                ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
                ISpPeriodicTimer timer = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 1000));
                ISpEventListner listner = new SimpleEventListner();

                listner.ResponseReceived += new Action<ISpEventMessage>((msg) => { });

                // TODO - Need a default response msg

                // Simulates DI
                SpStateMachineEngine engine =
                new SpStateMachineEngine(listner, store, behavior, sm, timer);

                engine.Start();

                Thread.Sleep(3000);

                //sm.Tick(new BaseMsg(99, 456));

                //listner.PostMessage(new SpBaseMsg(MyMessageType 777, 12345));

                listner.PostMessage(new MyBaseMsg(MyMsgType.SimpleMsg, MyEventType.Stop));

                Thread.Sleep(3000);
                engine.Stop();

                Console.WriteLine("Disposing Engine - thread should not output while I wait 3 seconds");
                engine.Dispose();

                Thread.Sleep(3000);
                Console.WriteLine("Done");

                // Multi call test
                engine.Dispose();
                engine.Dispose();
                engine.Dispose();
                Console.WriteLine("Engine Disposed");

                //SpState<DataClass> state = new SpState<DataClass>(dataClass);
                //SpStateMachine<DataClass> stateMachine = new SpStateMachine<DataClass>(dataClass, state);

            });
        }