SelectionTests.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using PixiEditor.Helpers;
  2. using PixiEditor.Models.DataHolders;
  3. using PixiEditor.Models.Enums;
  4. using PixiEditor.Models.Position;
  5. using System;
  6. using System.Collections.Generic;
  7. using Xunit;
  8. namespace PixiEditorTests.ModelsTests.DataHoldersTests;
  9. public class SelectionTests
  10. {
  11. [Fact]
  12. public void TestThatSetSelectionNewSetsCorrectSelection()
  13. {
  14. Selection selection = new Selection(Array.Empty<Coordinates>(), new(10, 10));
  15. Coordinates[] points = { new Coordinates(0, 0), new Coordinates(1, 1) };
  16. selection.SetSelection(points, SelectionType.New);
  17. selection.SetSelection(points, SelectionType.New); // Doing it twice, to check if it sets every time properly
  18. Assert.Equal(points.Length, selection.SelectedPoints.Count);
  19. }
  20. [Fact]
  21. public void TestThatSetSelectionAddSetsCorrectSelection()
  22. {
  23. Selection selection = new Selection(Array.Empty<Coordinates>(), new PixelSize(10, 10));
  24. Coordinates[] points = { new Coordinates(0, 0), new Coordinates(1, 1) };
  25. Coordinates[] points2 = { new Coordinates(2, 4), new Coordinates(5, 7) };
  26. selection.SetSelection(points, SelectionType.Add);
  27. selection.SetSelection(points2, SelectionType.Add); // Doing it twice, to check if it sets every time properly
  28. Assert.Equal(points.Length + points2.Length, selection.SelectedPoints.Count);
  29. }
  30. [Fact]
  31. public void TestThatSetSelectionSubtractSetsCorrectSelection()
  32. {
  33. Selection selection = new Selection(Array.Empty<Coordinates>(), new PixelSize(10, 10));
  34. Coordinates[] points = { new Coordinates(0, 0), new Coordinates(1, 1) };
  35. Coordinates[] points2 = { new Coordinates(1, 1) };
  36. selection.SetSelection(points, SelectionType.Add);
  37. selection.SetSelection(points2, SelectionType.Subtract); // Doing it twice, to check if it sets every time properly
  38. Assert.Single(selection.SelectedPoints);
  39. }
  40. [Fact]
  41. public void TestClearWorks()
  42. {
  43. Selection selection = new Selection(new[] { new Coordinates(0, 0), new Coordinates(5, 7) }, new PixelSize(10, 10));
  44. selection.Clear();
  45. Assert.Empty(selection.SelectedPoints);
  46. Assert.Equal(1, selection.SelectionLayer.Width);
  47. Assert.Equal(1, selection.SelectionLayer.Height);
  48. }
  49. [Fact]
  50. public void TestThatUndoWorks()
  51. {
  52. using Document document = new Document(10, 10);
  53. IEnumerable<Coordinates> oldSelection = new List<Coordinates>(document.ActiveSelection.SelectedPoints);
  54. document.ActiveSelection.SetSelection(new[] { new Coordinates(0, 0), new Coordinates(5, 7) }, SelectionType.Add);
  55. Assert.NotEqual(oldSelection, document.ActiveSelection.SelectedPoints);
  56. SelectionHelpers.AddSelectionUndoStep(document, oldSelection, SelectionType.Add);
  57. document.UndoManager.Undo();
  58. Assert.Equal(oldSelection, document.ActiveSelection.SelectedPoints);
  59. }
  60. }