static void Main(string[] args) { string fileName = "statemachine.dat"; { PeristenceActuator actuator = new PeristenceActuator(); PersistenceContext context = new PersistenceContext(actuator); context.EvOn(); Console.WriteLine(context.StateCurrent.Name); using (StreamWriter streamWriter = File.CreateText(fileName)) { context.Serialize(streamWriter); } } { PeristenceActuator actuator = new PeristenceActuator(); PersistenceContext context = new PersistenceContext(actuator); using (StreamReader streamReader = new StreamReader(fileName)) { context.DeSerialize(streamReader); } Console.WriteLine(context.StateCurrent.Name); } Environment.Exit(0); }
public void PersistenceOn() { // Create, change state and Serialize PersistenceContext context = new PersistenceContext(this.actuator); Assert.AreEqual(context.StateCurrent.Name, "Off"); context.EvOn(); Assert.AreEqual(context.StateCurrent.Name, "On"); string fileName = context.Name + "On.dat"; Serialize(context, fileName); // Create new , DeSerialize and check state PersistenceContext contextSerialized = new PersistenceContext(actuator); Assert.AreEqual(contextSerialized.StateCurrent.Name, "Off"); DeSerialize(contextSerialized, fileName); Assert.AreEqual(contextSerialized.StateCurrent.Name, "On"); }