コード例 #1
0
        public void CanSaveState()
        {
            var originator = new Originator(15);
            var memento = originator.SaveState();

            Assert.AreEqual(15, memento.State);

            originator = new Originator(256);
            originator.SetState(memento);

            Assert.AreEqual(15, originator.State);
        }
コード例 #2
0
        public void CanUserCaretaker()
        {
            var c = new Caretaker();
            var o = new Originator(0);

            //I stack the different states of the object
            for (int i = 0; i < 10; i++)
            {
                o.State = i;
                c.PushState(o);
            }

            //I unstack the different state of the object
            for (int i = 10; i < 0; i--)
            {
                c.PopState(o);
                Assert.AreEqual(i, o.State);
            }
        }
コード例 #3
0
 public void PushState(Originator originator)
 {
     var memento = originator.SaveState();
     this.stack.Push(memento);
 }
コード例 #4
0
 public void PopState(Originator originator)
 {
     var memento = this.stack.Pop();
     originator.SetState(memento);
 }