|
@@ -1,4 +1,5 @@
|
|
|
-using PixiEditor.Models.Controllers;
|
|
|
+using System;
|
|
|
+using PixiEditor.Models.Controllers;
|
|
|
using PixiEditor.Models.DataHolders;
|
|
|
using Xunit;
|
|
|
|
|
@@ -8,6 +9,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
{
|
|
|
|
|
|
public int ExampleProperty { get; set; } = 1;
|
|
|
+ public TestPropertyClass TestPropClass { get; set; } = new TestPropertyClass();
|
|
|
|
|
|
[Fact]
|
|
|
public void TestSetRoot()
|
|
@@ -19,7 +21,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
[Fact]
|
|
|
public void TestAddToUndoStack()
|
|
|
{
|
|
|
- PrepareUnoManagerForTests();
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
Assert.True(UndoManager.UndoStack.Count == 1);
|
|
|
Assert.True((int)UndoManager.UndoStack.Peek().OldValue == ExampleProperty);
|
|
@@ -28,7 +30,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
[Fact]
|
|
|
public void TestThatUndoAddsToRedoStack()
|
|
|
{
|
|
|
- PrepareUnoManagerForTests();
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
UndoManager.Undo();
|
|
|
Assert.True(UndoManager.RedoStack.Count == 1);
|
|
@@ -37,7 +39,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
[Fact]
|
|
|
public void TestUndo()
|
|
|
{
|
|
|
- PrepareUnoManagerForTests();
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
|
|
|
ExampleProperty = 55;
|
|
|
UndoManager.Undo();
|
|
@@ -48,7 +50,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
[Fact]
|
|
|
public void TestThatRedoAddsToUndoStack()
|
|
|
{
|
|
|
- PrepareUnoManagerForTests();
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
UndoManager.Undo();
|
|
|
UndoManager.Redo();
|
|
@@ -58,7 +60,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
[Fact]
|
|
|
public void TestRedo()
|
|
|
{
|
|
|
- PrepareUnoManagerForTests();
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
ExampleProperty = 55;
|
|
|
UndoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
|
|
|
UndoManager.Undo();
|
|
@@ -66,12 +68,113 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
Assert.True((int)UndoManager.UndoStack.Peek().NewValue == ExampleProperty);
|
|
|
}
|
|
|
|
|
|
- private void PrepareUnoManagerForTests()
|
|
|
+ [Fact]
|
|
|
+ public void TestThatUndoManagerUndoAndRedoWithCustomRootCorrectly()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
+ TestPropertyClass testProp = new TestPropertyClass();
|
|
|
+ int newVal = 5;
|
|
|
+ testProp.IntProperty = newVal;
|
|
|
+ UndoManager.AddUndoChange(new Change("IntProperty", 0, newVal, root: testProp));
|
|
|
+ Assert.Equal(newVal, testProp.IntProperty);
|
|
|
+
|
|
|
+ UndoManager.Undo();
|
|
|
+
|
|
|
+ Assert.Equal(0, testProp.IntProperty);
|
|
|
+
|
|
|
+ UndoManager.Redo();
|
|
|
+
|
|
|
+ Assert.Equal(newVal, testProp.IntProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void TestThatMixedProcessOfUndoAndRedoWorks()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
+
|
|
|
+
|
|
|
+ int newVal = 5;
|
|
|
+
|
|
|
+
|
|
|
+ UndoManager.AddUndoChange(
|
|
|
+ new Change("ExampleProperty",
|
|
|
+ ReverseProcess,
|
|
|
+ new object[]{ExampleProperty},
|
|
|
+ newVal));
|
|
|
+
|
|
|
+ ExampleProperty = newVal;
|
|
|
+
|
|
|
+ Assert.Equal(newVal, ExampleProperty);
|
|
|
+
|
|
|
+ UndoManager.Undo();
|
|
|
+
|
|
|
+ Assert.Equal(1, ExampleProperty);
|
|
|
+
|
|
|
+ UndoManager.Redo();
|
|
|
+
|
|
|
+ Assert.Equal(newVal, ExampleProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void TestThatProcessBasedUndoAndRedoWorks()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
+ int newVal = 5;
|
|
|
+ UndoManager.AddUndoChange(new Change(ReverseProcess, new object[]{ExampleProperty}, ReverseProcess,
|
|
|
+ new object[]{newVal}));
|
|
|
+
|
|
|
+ ExampleProperty = newVal;
|
|
|
+
|
|
|
+ Assert.Equal(newVal, ExampleProperty);
|
|
|
+
|
|
|
+ UndoManager.Undo();
|
|
|
+
|
|
|
+ Assert.Equal(1, ExampleProperty);
|
|
|
+
|
|
|
+ UndoManager.Redo();
|
|
|
+
|
|
|
+ Assert.Equal(newVal, ExampleProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ [Fact]
|
|
|
+ public void TestThatNestedPropertyUndoWorks()
|
|
|
+ {
|
|
|
+ PrepareUnoManagerForTest();
|
|
|
+ int newVal = 5;
|
|
|
+
|
|
|
+ UndoManager.AddUndoChange(new Change("TestPropClass.IntProperty", TestPropClass.IntProperty,
|
|
|
+ newVal));
|
|
|
+
|
|
|
+ TestPropClass.IntProperty = newVal;
|
|
|
+
|
|
|
+ Assert.Equal(newVal, TestPropClass.IntProperty);
|
|
|
+
|
|
|
+ UndoManager.Undo();
|
|
|
+
|
|
|
+ Assert.Equal(0, TestPropClass.IntProperty);
|
|
|
+
|
|
|
+ UndoManager.Redo();
|
|
|
+
|
|
|
+ Assert.Equal(newVal, TestPropClass.IntProperty);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReverseProcess(object[] args)
|
|
|
+ {
|
|
|
+ ExampleProperty = (int)args[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PrepareUnoManagerForTest()
|
|
|
{
|
|
|
UndoManager.SetMainRoot(this);
|
|
|
UndoManager.UndoStack.Clear();
|
|
|
UndoManager.RedoStack.Clear();
|
|
|
ExampleProperty = 1;
|
|
|
+ TestPropClass = new TestPropertyClass();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public class TestPropertyClass
|
|
|
+ {
|
|
|
+ public int IntProperty { get; set; } = 0;
|
|
|
+ }
|
|
|
}
|