SelectionTests.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. {
  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(1, selection.SelectionLayer.Width);
  48. Assert.Equal(1, selection.SelectionLayer.Height);
  49. }
  50. [Fact]
  51. public void TestThatUndoWorks()
  52. {
  53. Document document = new Document(10, 10);
  54. IEnumerable<Coordinates> oldSelection = new List<Coordinates>(document.ActiveSelection.SelectedPoints);
  55. document.ActiveSelection.SetSelection(new[] { new Coordinates(0, 0), new Coordinates(5, 7) }, SelectionType.Add);
  56. Assert.NotEqual(oldSelection, document.ActiveSelection.SelectedPoints);
  57. SelectionHelpers.AddSelectionUndoStep(document, oldSelection, SelectionType.Add);
  58. document.UndoManager.Undo();
  59. Assert.Equal(oldSelection, document.ActiveSelection.SelectedPoints);
  60. }
  61. }
  62. }