PixelChangesControllerTests.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using PixiEditor.Models.Controllers;
  2. using PixiEditor.Models.DataHolders;
  3. using PixiEditor.Models.Position;
  4. using SkiaSharp;
  5. using System;
  6. using Xunit;
  7. namespace PixiEditorTests.ModelsTests.ControllersTests
  8. {
  9. public class PixelChangesControllerTests
  10. {
  11. [Fact]
  12. public void TestThatPopChangesPopsChanges()
  13. {
  14. PixelChangesController controller = CreateBasicController().Item2;
  15. System.Tuple<LayerChange, LayerChange>[] changes = controller.PopChanges();
  16. Assert.NotEmpty(changes);
  17. Assert.Null(controller.PopChanges());
  18. }
  19. [Fact]
  20. public void TestThatAddChangesAddsAsNewChange()
  21. {
  22. var data = CreateBasicController();
  23. PixelChangesController controller = data.Item2;
  24. Coordinates[] cords = { new Coordinates(5, 3), new Coordinates(7, 2) };
  25. Guid guid = Guid.NewGuid();
  26. controller.AddChanges(
  27. new LayerChange(
  28. BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Black), guid),
  29. new LayerChange(BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Transparent), guid));
  30. System.Tuple<LayerChange, LayerChange>[] changes = controller.PopChanges();
  31. Assert.Equal(2, changes.Length);
  32. }
  33. [Fact]
  34. public void TestThatAddChangesAddsToExistingChange()
  35. {
  36. Coordinates[] cords2 = { new Coordinates(2, 2), new Coordinates(5, 5) };
  37. var data = CreateBasicController();
  38. PixelChangesController controller = data.Item2;
  39. controller.AddChanges(
  40. new LayerChange(
  41. BitmapPixelChanges.FromSingleColoredArray(cords2, SKColors.Black), data.Item1),
  42. new LayerChange(BitmapPixelChanges.FromSingleColoredArray(cords2, SKColors.Transparent), data.Item1));
  43. Tuple<LayerChange, LayerChange>[] changes = controller.PopChanges();
  44. Assert.Single(changes);
  45. Assert.Equal(4, changes[0].Item1.PixelChanges.ChangedPixels.Count);
  46. Assert.Equal(4, changes[0].Item2.PixelChanges.ChangedPixels.Count);
  47. }
  48. private static Tuple<Guid, PixelChangesController> CreateBasicController()
  49. {
  50. Coordinates[] cords = { new Coordinates(0, 0), new Coordinates(1, 1) };
  51. PixelChangesController controller = new PixelChangesController();
  52. Guid guid = Guid.NewGuid();
  53. controller.AddChanges(
  54. new LayerChange(
  55. BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Black), guid),
  56. new LayerChange(BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Transparent), guid));
  57. return new Tuple<Guid, PixelChangesController>(guid, controller);
  58. }
  59. }
  60. }