public void Test()
        {
            var originator = new Originator("field 2", 42)
            {
                Property1 = "property 1",
                Field1 = "field 1"
            };

            Assert.That(originator.Field1, Is.EqualTo("field 1"));
            Assert.That(originator.GetField2(), Is.EqualTo("field 2"));
            Assert.That(originator.Property1, Is.EqualTo("property 1"));
            Assert.That(originator.Property2, Is.EqualTo(42));

            var memento = new Memento<Originator>(originator);

            originator.Field1 = "field 1a";
            originator.SetField2("field 2a");
            originator.Property1 = "property 1a";
            originator.SetProperty2(52);

            Assert.That(originator.Field1, Is.EqualTo("field 1a"));
            Assert.That(originator.GetField2(), Is.EqualTo("field 2a"));
            Assert.That(originator.Property1, Is.EqualTo("property 1a"));
            Assert.That(originator.Property2, Is.EqualTo(52));

            memento.Restore(originator);

            Assert.That(originator.Field1, Is.EqualTo("field 1"));
            Assert.That(originator.GetField2(), Is.EqualTo("field 2"));
            Assert.That(originator.Property1, Is.EqualTo("property 1"));
            Assert.That(originator.Property2, Is.EqualTo(42));
        }
Exemple #2
0
        public void StateRestores()
        {
            // Save the original state of the originator
            _memento           = _originator.CreateMemento();
            _caretaker.Memento = _memento;

            var originalState = _originator.CurrentState;

            // Switch the state
            _originator.SwitchState();

            // Restore to the original state
            _originator.RestoreState(_caretaker.Memento);

            Assert.AreEqual(originalState, _originator.CurrentState);
        }
 // Restores original state
 public void SetMemento(Memento memento)
 {
     Console.WriteLine("Restoring state...");
     State = memento.State;
 }
Exemple #4
0
 public MementoTest()
 {
     _memento    = new DesignPatterns.Behavioral.Memento.Memento();
     _originator = new Originator();
     _caretaker  = new Caretaker();
 }
Exemple #5
0
 public void SetMemento(Memento memento)
 {
     Debug.WriteLine("Restoring state...");
     State = memento.State;
 }
Exemple #6
0
 public void Restore(Memento memento)
 {
     State = memento.GetState();
 }