public void BikeRace_Restore_RestoresBikeRace() { // Arrange BikeRace race = new BikeRace(new string[] { "Tom", "Dick", "Harry" }); // Act race.RunToCheckPoint(); CheckPointSave checkpointOne = new CheckPointSave(race.Save()); race.RunToCheckPoint(); race.Restore(checkpointOne.Restore()); // Assert Assert.AreSame(race.GetRace(), checkpointOne.Restore()); }
public static void Run() { Console.WriteLine($"{Environment.NewLine}*** MEMENTO PATTERN ***{Environment.NewLine}"); BikeRace race = new BikeRace(new string[] { "Tom", "Dick", "Harry", "Bill", "Jim", "Rick", "Fred", "Joe", "Dan", "Gav", "Mark", "Henry" }); // Run to first checkpoint race.RunToCheckPoint(); race.DisplayTheRace(); CheckPointSave checkpointOne = new CheckPointSave(race.Save()); race.RunToCheckPoint(); race.DisplayTheRace(); // Return to the saved state race.Restore(checkpointOne.Restore()); race.DisplayTheRace(); }