UndoManagerTests.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using PixiEditor.Models.Controllers;
  2. using PixiEditor.Models.DataHolders;
  3. using Xunit;
  4. namespace PixiEditorTests.ModelsTests.ControllersTests
  5. {
  6. public class UndoManagerTests
  7. {
  8. public int ExampleProperty { get; set; } = 1;
  9. [Fact]
  10. public void TestSetRoot()
  11. {
  12. UndoManager.SetMainRoot(this);
  13. Assert.Equal(this, UndoManager.MainRoot);
  14. }
  15. [Fact]
  16. public void TestAddToUndoStack()
  17. {
  18. PrepareUnoManagerForTests();
  19. UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
  20. Assert.True(UndoManager.UndoStack.Count == 1);
  21. Assert.True((int)UndoManager.UndoStack.Peek().OldValue == ExampleProperty);
  22. }
  23. [Fact]
  24. public void TestThatUndoAddsToRedoStack()
  25. {
  26. PrepareUnoManagerForTests();
  27. UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
  28. UndoManager.Undo();
  29. Assert.True(UndoManager.RedoStack.Count == 1);
  30. }
  31. [Fact]
  32. public void TestUndo()
  33. {
  34. PrepareUnoManagerForTests();
  35. UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
  36. ExampleProperty = 55;
  37. UndoManager.Undo();
  38. Assert.True((int)UndoManager.RedoStack.Peek().OldValue == ExampleProperty);
  39. }
  40. [Fact]
  41. public void TestThatRedoAddsToUndoStack()
  42. {
  43. PrepareUnoManagerForTests();
  44. UndoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
  45. UndoManager.Undo();
  46. UndoManager.Redo();
  47. Assert.True(UndoManager.UndoStack.Count == 1);
  48. }
  49. [Fact]
  50. public void TestRedo()
  51. {
  52. PrepareUnoManagerForTests();
  53. ExampleProperty = 55;
  54. UndoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
  55. UndoManager.Undo();
  56. UndoManager.Redo();
  57. Assert.True((int)UndoManager.UndoStack.Peek().NewValue == ExampleProperty);
  58. }
  59. private void PrepareUnoManagerForTests()
  60. {
  61. UndoManager.SetMainRoot(this);
  62. UndoManager.UndoStack.Clear();
  63. UndoManager.RedoStack.Clear();
  64. ExampleProperty = 1;
  65. }
  66. }
  67. }