PixelChangesControllerTests.cs 2.9 KB

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