SelectionTests.cs 3.0 KB

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