private void ApplyUndoRedoState(UndoRedoState state)
 {
     switch (state.Type)
     {
         case UndoRedoType.FileValues:
             this.PasteValuesToCurrentFile(state.Values);
             break;
         default:
             throw new NotSupportedException(String.Format("Unhandled undo/redo state type {0}.", state.Type));
     }
 }
        public void UndoRedo()
        {
            // zero states
            UndoRedoChain undoRedoChain = new UndoRedoChain();
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.CanUndo);
            UndoRedoState state;
            Assert.IsFalse(undoRedoChain.TryGetRedo(out state));
            Assert.IsFalse(undoRedoChain.TryGetUndo(out state));

            // basic lifecycle with two different states
            FileDatabase fileDatabase = this.CreateFileDatabase(TestConstant.File.DefaultTemplateDatabaseFileName, TestConstant.File.DefaultNewFileDatabaseFileName);
            this.PopulateDefaultDatabase(fileDatabase);
            ImageRow firstFile = fileDatabase.Files[0];
            ImageRow secondFile = fileDatabase.Files[1];
            undoRedoChain.AddStateIfDifferent(firstFile);
            undoRedoChain.AddStateIfDifferent(secondFile);
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsTrue(undoRedoChain.CanUndo);

            Assert.IsTrue(undoRedoChain.TryGetUndo(out state));
            Assert.IsTrue(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.CanUndo);

            Assert.IsTrue(undoRedoChain.TryGetRedo(out state));
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsTrue(undoRedoChain.CanUndo);

            Assert.IsTrue(undoRedoChain.TryGetUndo(out state));
            Assert.IsTrue(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.CanUndo);

            Assert.IsTrue(undoRedoChain.TryGetRedo(out state));
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsTrue(undoRedoChain.CanUndo);

            Assert.IsFalse(undoRedoChain.TryGetRedo(out state));
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsTrue(undoRedoChain.CanUndo);

            Assert.IsTrue(undoRedoChain.TryGetUndo(out state));
            Assert.IsTrue(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.CanUndo);

            Assert.IsFalse(undoRedoChain.TryGetUndo(out state));
            Assert.IsTrue(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.CanUndo);

            undoRedoChain.Clear();
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.CanUndo);
            Assert.IsFalse(undoRedoChain.TryGetRedo(out state));
            Assert.IsFalse(undoRedoChain.TryGetUndo(out state));

            // one state
            UndoRedoState firstState = new UndoRedoState(firstFile);
            undoRedoChain.AddStateIfDifferent(firstFile);
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsTrue(undoRedoChain.CanUndo);
            Assert.IsFalse(undoRedoChain.TryGetRedo(out state));
            Assert.IsTrue(undoRedoChain.TryGetUndo(out state));
            Assert.IsTrue(firstState.Equals(state));

            undoRedoChain.AddStateIfDifferent(firstFile);
            Assert.IsFalse(undoRedoChain.CanRedo);
            Assert.IsFalse(undoRedoChain.TryGetRedo(out state));
            Assert.IsTrue(undoRedoChain.TryGetUndo(out state));
            Assert.IsTrue(firstState.Equals(state));
        }