UndoManagerTests.cs 2.5 KB

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