1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using PixiEditor.Models.Controllers;
- using PixiEditor.Models.DataHolders;
- using Xunit;
- namespace PixiEditorTests.ModelsTests.ControllersTests
- {
- public class UndoManagerTests
- {
- public int ExampleProperty { get; set; } = 1;
- [Fact]
- public void TestSetRoot()
- {
- UndoManager.SetMainRoot(this);
- Assert.Equal(this, UndoManager.MainRoot);
- }
- [Fact]
- public void TestAddToUndoStack()
- {
- PrepareUnoManagerForTests();
- UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
- Assert.True(UndoManager.UndoStack.Count == 1);
- Assert.True((int)UndoManager.UndoStack.Peek().OldValue == ExampleProperty);
- }
- [Fact]
- public void TestThatUndoAddsToRedoStack()
- {
- PrepareUnoManagerForTests();
- UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
- UndoManager.Undo();
- Assert.True(UndoManager.RedoStack.Count == 1);
- }
- [Fact]
- public void TestUndo()
- {
- PrepareUnoManagerForTests();
- UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
- ExampleProperty = 55;
- UndoManager.Undo();
- Assert.True((int)UndoManager.RedoStack.Peek().OldValue == ExampleProperty);
- }
- [Fact]
- public void TestThatRedoAddsToUndoStack()
- {
- PrepareUnoManagerForTests();
- UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
- UndoManager.Undo();
- UndoManager.Redo();
- Assert.True(UndoManager.UndoStack.Count == 1);
- }
- [Fact]
- public void TestRedo()
- {
- PrepareUnoManagerForTests();
- ExampleProperty = 55;
- UndoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
- UndoManager.Undo();
- UndoManager.Redo();
- Assert.True((int)UndoManager.UndoStack.Peek().NewValue == ExampleProperty);
- }
- private void PrepareUnoManagerForTests()
- {
- UndoManager.SetMainRoot(this);
- UndoManager.UndoStack.Clear();
- UndoManager.RedoStack.Clear();
- ExampleProperty = 1;
- }
- }
- }
|