PixelChangesControllerTests.cs 2.5 KB

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