示例#1
0
        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());
        }
示例#2
0
        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();
        }