Example #1
0
        public static void SerializationAndDeserialization()
        {
            var stateMachine = new StateMachine();
            var stateA = stateMachine.CreateInitialState("StateA");
            var stateB = stateMachine.CreateState("StateB");

            var evt = new Event();
            stateA.TransitionOn(evt).To(stateB);

            // Move us out of the default state
            evt.Fire();
            Assert.AreEqual(stateB, stateMachine.CurrentState);

            string serialized = stateMachine.Serialize();

            // Reset the state machine
            stateMachine.Reset();
            Assert.AreEqual(stateA, stateMachine.CurrentState);

            // Deserialize into it
            stateMachine.Deserialize(serialized);
            Assert.AreEqual(stateB, stateMachine.CurrentState);
        }