|
@@ -0,0 +1,81 @@
|
|
|
+using NUnit.Framework;
|
|
|
+using PixiEditorDotNetCore3.Models.Controllers;
|
|
|
+using PixiEditorDotNetCore3.Models.DataHolders;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
+
|
|
|
+namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
+{
|
|
|
+ [TestFixture]
|
|
|
+ public class UndoManagerTests
|
|
|
+ {
|
|
|
+
|
|
|
+ public int ExampleProperty { get; set; } = 1;
|
|
|
+
|
|
|
+ [TestCase]
|
|
|
+ public void TestSetRoot()
|
|
|
+ {
|
|
|
+ UndoManager.SetMainRoot(this);
|
|
|
+ Assert.AreEqual(this, UndoManager.MainRoot);
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestCase]
|
|
|
+ public void TestAddToUndoStack()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTests();
|
|
|
+ UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
+ Assert.IsTrue(UndoManager.UndoStack.Count == 1);
|
|
|
+ Assert.IsTrue((int)UndoManager.UndoStack.Peek().OldValue == ExampleProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestCase]
|
|
|
+ public void TestThatUndoAddsToRedoStack()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTests();
|
|
|
+ UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
+ UndoManager.Undo();
|
|
|
+ Assert.IsTrue(UndoManager.RedoStack.Count == 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestCase]
|
|
|
+ public void TestUndo()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTests();
|
|
|
+ UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
|
|
|
+ ExampleProperty = 55;
|
|
|
+ UndoManager.Undo();
|
|
|
+ Assert.IsTrue((int)UndoManager.RedoStack.Peek().OldValue == ExampleProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ [TestCase]
|
|
|
+ public void TestThatRedoAddsToUndoStack()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTests();
|
|
|
+ UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
+ UndoManager.Undo();
|
|
|
+ UndoManager.Redo();
|
|
|
+ Assert.IsTrue(UndoManager.UndoStack.Count == 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ [TestCase]
|
|
|
+ public void TestRedo()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTests();
|
|
|
+ ExampleProperty = 55;
|
|
|
+ UndoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
|
|
|
+ UndoManager.Undo();
|
|
|
+ UndoManager.Redo();
|
|
|
+ Assert.IsTrue((int)UndoManager.UndoStack.Peek().NewValue == ExampleProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PrepareUnoManagerForTests()
|
|
|
+ {
|
|
|
+ UndoManager.SetMainRoot(this);
|
|
|
+ UndoManager.UndoStack.Clear();
|
|
|
+ UndoManager.RedoStack.Clear();
|
|
|
+ ExampleProperty = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|