public void _0_Base_MutilDisposed()
 {
     TestHelpers.CatchUnexpected(() => {
         ISpEventStore d = new SimpleDequeEventStore(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Dispose();
         d.Dispose();
         d.Dispose();
     });
 }
 public void _0_PriorityEventStore_Add()
 {
     TestHelpers.CatchUnexpected(() => {
         ISpEventStore d = new SimpleDequeEventStore(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Add(new SpBaseEventMsg(new SpIntToInt(1), new SpIntToInt(100), SpEventPriority.Undefined));
         d.Add(new SpBaseEventMsg(new SpIntToInt(1), new SpIntToInt(100), SpEventPriority.High));
         d.Add(new SpBaseEventMsg(new SpIntToInt(1), new SpIntToInt(100), SpEventPriority.Normal));
         d.Add(new SpBaseEventMsg(new SpIntToInt(1), new SpIntToInt(100), SpEventPriority.Low));
     });
 }
 public void _50112_Base_Add_NullMsg()
 {
     TestHelpers.CatchExpected(50112, "BaseEventStore", "Add", "Null msg Argument", () => {
         ISpEventStore d = new SimpleDequeEventStore(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Add(null);
     });
 }
 public void _50113_Base_Get_Disposed()
 {
     TestHelpers.CatchExpected(50113, "BaseEventStore", "Get", "Attempting to use Disposed Object", () => {
         ISpEventStore d = new SimpleDequeEventStore(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Dispose();
         d.Get();
     });
 }
 public void _50110_Base_Constructor_NullParam()
 {
     TestHelpers.CatchExpected(50110, "BaseEventStore", ".ctor", "Null defaultTick Argument", () => {
         ISpEventStore d = new SimpleDequeEventStore(null);
     });
 }
        public void _0_SimpleDequeQueue_AddSequencing()
        {
            ISpEventStore d = null;
            TestHelpers.CatchUnexpected(() => {
                d = new SimpleDequeEventStore(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
                d.Add(new SpBaseEventMsg(new SpIntToInt(1), new SpIntToInt(101)));
                d.Add(new SpBaseEventMsg(new SpIntToInt(2), new SpIntToInt(102)));
                d.Add(new SpBaseEventMsg(new SpIntToInt(3), new SpIntToInt(103)));
            });

            this.MsgEqual(new SpBaseEventMsg(new SpIntToInt(1), new SpIntToInt(101)), d.Get());
            this.MsgEqual(new SpBaseEventMsg(new SpIntToInt(2), new SpIntToInt(102)), d.Get());
            this.MsgEqual(new SpBaseEventMsg(new SpIntToInt(3), new SpIntToInt(103)), d.Get());
            this.MsgEqual(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)), d.Get());

            TestHelpers.CatchUnexpected(() => {
                d.Dispose();
            });
        }
 public void _0_SimpleDequeQueue_Add()
 {
     TestHelpers.CatchUnexpected(() => {
         ISpEventStore d = new SimpleDequeEventStore(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Add(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Add(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
         d.Add(new SpBaseEventMsg(new SpIntToInt(25), new SpIntToInt(100)));
     });
 }
        private SpStateMachineEngine GetEngine(out ISpEventListner listner, MyDataClass dataClass, ISpState firstState)
        {
            ISpStateMachine sm = new MyStateMachine(dataClass, firstState);
            ISpEventStore store = new SimpleDequeEventStore(new MyTickMsg());
            ISpBehaviorOnEvent behavior = new SpPeriodicWakeupOnly();
            ISpPeriodicTimer timer = new WinSimpleTimer(new TimeSpan(0, 0, 0, 0, 500));
            //ISpEventListner listner = new SimpleEventListner();
            listner = new SimpleEventListner();

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

            // Simulates DI
            return new SpStateMachineEngine(listner, store, behavior, sm, timer);
        }
        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);

            });
        }