|
@@ -1,5 +1,4 @@
|
|
|
using PixiEditor.Models.Controllers;
|
|
|
-using PixiEditor.Models.DataHolders;
|
|
|
using PixiEditor.Models.Undo;
|
|
|
using Xunit;
|
|
|
|
|
@@ -20,7 +19,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestSetRoot()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
Assert.Equal(this, undoManager.MainRoot);
|
|
|
}
|
|
|
|
|
@@ -28,9 +27,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestAddToUndoStack()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
+ using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
Assert.True(undoManager.UndoStack.Count == 1);
|
|
|
Assert.True((int)undoManager.UndoStack.Peek().OldValue == ExampleProperty);
|
|
|
}
|
|
@@ -39,9 +39,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatUndoAddsToRedoStack()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
+ using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
undoManager.Undo();
|
|
|
Assert.True(undoManager.RedoStack.Count == 1);
|
|
|
}
|
|
@@ -50,9 +51,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestUndo()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
|
|
|
+ using var change = new Change("ExampleProperty", ExampleProperty, 55);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
ExampleProperty = 55;
|
|
|
undoManager.Undo();
|
|
|
Assert.True((int)undoManager.RedoStack.Peek().OldValue == ExampleProperty);
|
|
@@ -62,9 +64,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatRedoAddsToUndoStack()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
|
|
|
+ using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
undoManager.Undo();
|
|
|
undoManager.Redo();
|
|
|
Assert.True(undoManager.UndoStack.Count == 1);
|
|
@@ -74,10 +77,11 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestRedo()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
ExampleProperty = 55;
|
|
|
- undoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
|
|
|
+ using var change = new Change("ExampleProperty", 1, ExampleProperty);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
undoManager.Undo();
|
|
|
undoManager.Redo();
|
|
|
Assert.True((int)undoManager.UndoStack.Peek().NewValue == ExampleProperty);
|
|
@@ -87,12 +91,13 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatUndoManagerUndoAndRedoWithCustomRootCorrectly()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
TestPropertyClass testProp = new TestPropertyClass();
|
|
|
int newVal = 5;
|
|
|
testProp.IntProperty = newVal;
|
|
|
- undoManager.AddUndoChange(new Change("IntProperty", 0, newVal, root: testProp));
|
|
|
+ using var change = new Change("IntProperty", 0, newVal, root: testProp);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
Assert.Equal(newVal, testProp.IntProperty);
|
|
|
|
|
|
undoManager.Undo();
|
|
@@ -108,16 +113,15 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatMixedProcessOfUndoAndRedoWorks()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
int newVal = 5;
|
|
|
-
|
|
|
- undoManager.AddUndoChange(
|
|
|
- new Change(
|
|
|
+ using var change = new Change(
|
|
|
"ExampleProperty",
|
|
|
ReverseProcess,
|
|
|
new object[] { ExampleProperty },
|
|
|
- newVal));
|
|
|
+ newVal);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
|
|
|
ExampleProperty = newVal;
|
|
|
|
|
@@ -136,14 +140,15 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatProcessBasedUndoAndRedoWorks()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
int newVal = 5;
|
|
|
- undoManager.AddUndoChange(new Change(
|
|
|
+ using var change = new Change(
|
|
|
ReverseProcess,
|
|
|
new object[] { ExampleProperty },
|
|
|
ReverseProcess,
|
|
|
- new object[] { newVal }));
|
|
|
+ new object[] { newVal });
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
|
|
|
ExampleProperty = newVal;
|
|
|
|
|
@@ -162,11 +167,11 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatNestedPropertyUndoWorks()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
int newVal = 5;
|
|
|
-
|
|
|
- undoManager.AddUndoChange(new Change("TestPropClass.IntProperty", TestPropClass.IntProperty, newVal));
|
|
|
+ using var change = new Change("TestPropClass.IntProperty", TestPropClass.IntProperty, newVal);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
|
|
|
TestPropClass.IntProperty = newVal;
|
|
|
|
|
@@ -185,9 +190,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatFindRootProcessWorks()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));
|
|
|
+ using var change1 = new Change("IntProperty", 0, 5, FindRootProcess, null);
|
|
|
+ undoManager.AddUndoChange(change1);
|
|
|
|
|
|
Change change = undoManager.UndoStack.Peek();
|
|
|
|
|
@@ -198,9 +204,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatUndoForFindRootProcessWorks()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));
|
|
|
+ using var change = new Change("IntProperty", 0, 5, FindRootProcess, null);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
|
|
|
TestPropClass.IntProperty = 5;
|
|
|
|
|
@@ -213,9 +220,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
public void TestThatUndoAndRedoForFindRootProcessWorks()
|
|
|
{
|
|
|
PrepareUndoManagerForTest();
|
|
|
- UndoManager undoManager = new UndoManager(this);
|
|
|
+ using UndoManager undoManager = new UndoManager(this);
|
|
|
|
|
|
- undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));
|
|
|
+ using var change = new Change("IntProperty", 0, 5, FindRootProcess, null);
|
|
|
+ undoManager.AddUndoChange(change);
|
|
|
|
|
|
TestPropClass.IntProperty = 5;
|
|
|
|
|
@@ -244,4 +252,4 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
|
|
|
TestPropClass = new TestPropertyClass { IntProperty = 0 };
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|