BitmapManagerTests.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows;
  5. using System.Windows.Media;
  6. using PixiEditor;
  7. using PixiEditor.Models.Controllers;
  8. using PixiEditor.Models.DataHolders;
  9. using PixiEditor.Models.Layers;
  10. using PixiEditor.Models.Position;
  11. using PixiEditor.Models.Tools;
  12. using PixiEditor.Models.Tools.Tools;
  13. using PixiEditor.Models.Tools.ToolSettings;
  14. using Xunit;
  15. namespace PixiEditorTests.ModelsTests.ControllersTests
  16. {
  17. public class BitmapManagerTests
  18. {
  19. [Fact]
  20. public void TestThatBitmapManagerSetsCorrectTool()
  21. {
  22. BitmapManager bitmapManager = new BitmapManager();
  23. bitmapManager.SetActiveTool(new MockedSinglePixelPen());
  24. Assert.Equal(ToolType.Pen, bitmapManager.SelectedTool.ToolType);
  25. }
  26. [Fact]
  27. public void TestThatBitmapManagerAddsEmptyNewLayer()
  28. {
  29. string layerName = "TestLayer";
  30. BitmapManager bitmapManager = new BitmapManager
  31. {
  32. ActiveDocument = new Document(10, 10)
  33. };
  34. bitmapManager.AddNewLayer(layerName);
  35. Assert.Single(bitmapManager.ActiveDocument.Layers);
  36. Assert.Equal(layerName, bitmapManager.ActiveDocument.ActiveLayer.Name);
  37. Assert.Equal(0, bitmapManager.ActiveDocument.ActiveLayer.Width + bitmapManager.ActiveDocument.ActiveLayer.Height);
  38. }
  39. [Fact]
  40. public void TestThatBitmapManagerRemovesLayer()
  41. {
  42. BitmapManager bitmapManager = new BitmapManager
  43. {
  44. ActiveDocument = new Document(10, 10)
  45. };
  46. bitmapManager.AddNewLayer("_");
  47. bitmapManager.AddNewLayer("_1");
  48. Assert.Equal(2,bitmapManager.ActiveDocument.Layers.Count);
  49. bitmapManager.RemoveLayer(0);
  50. Assert.Single(bitmapManager.ActiveDocument.Layers);
  51. }
  52. [Fact]
  53. public void TestThatGeneratePreviewLayerGeneratesPreviewLayer()
  54. {
  55. BitmapManager bitmapManager = new BitmapManager
  56. {
  57. ActiveDocument = new Document(10, 10)
  58. };
  59. bitmapManager.GeneratePreviewLayer();
  60. Assert.NotNull(bitmapManager.PreviewLayer);
  61. Assert.Equal(0, bitmapManager.PreviewLayer.Width + bitmapManager.PreviewLayer.Height); //Size is zero
  62. Assert.Equal(0, bitmapManager.PreviewLayer.OffsetX + bitmapManager.PreviewLayer.OffsetY); //Offset is zero
  63. Assert.Equal(bitmapManager.ActiveDocument.Width,bitmapManager.PreviewLayer.MaxWidth);
  64. Assert.Equal(bitmapManager.ActiveDocument.Height,bitmapManager.PreviewLayer.MaxHeight);
  65. }
  66. [Fact]
  67. public void TestThatIsOperationToolWorks()
  68. {
  69. MockedSinglePixelPen singlePixelPen = new MockedSinglePixelPen();
  70. Assert.True(BitmapManager.IsOperationTool(singlePixelPen));
  71. }
  72. [StaFact]
  73. public void TestThatBitmapChangesExecuteToolExecutesPenTool()
  74. {
  75. BitmapManager bitmapManager = new BitmapManager
  76. {
  77. ActiveDocument = new Document(5, 5)
  78. };
  79. bitmapManager.AddNewLayer("Layer");
  80. bitmapManager.SetActiveTool(new MockedSinglePixelPen());
  81. bitmapManager.PrimaryColor = Colors.Green;
  82. bitmapManager.MouseController.StartRecordingMouseMovementChanges(true);
  83. bitmapManager.MouseController.RecordMouseMovementChange(new Coordinates(1, 1));
  84. bitmapManager.MouseController.StopRecordingMouseMovementChanges();
  85. bitmapManager.ExecuteTool(new Coordinates(1, 1));
  86. Assert.Equal(Colors.Green, bitmapManager.ActiveLayer.GetPixelWithOffset(1, 1));
  87. }
  88. }
  89. public class MockedSinglePixelPen : BitmapOperationTool
  90. {
  91. public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
  92. {
  93. return Only(
  94. BitmapPixelChanges.FromSingleColoredArray(new[] {mouseMove[0]}, color),0);
  95. }
  96. public override ToolType ToolType { get; } = ToolType.Pen;
  97. }
  98. }