SelectionTests.cs 2.3 KB

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