BitmapManagerTests.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System.Windows.Media;
  2. using PixiEditor.Models.Controllers;
  3. using PixiEditor.Models.DataHolders;
  4. using PixiEditor.Models.Position;
  5. using PixiEditor.Models.Tools;
  6. using PixiEditor.Models.Undo;
  7. using PixiEditorTests.ModelsTests.ColorsTests;
  8. using Xunit;
  9. namespace PixiEditorTests.ModelsTests.ControllersTests
  10. {
  11. public class BitmapManagerTests
  12. {
  13. [Fact]
  14. public void TestThatBitmapManagerSetsCorrectTool()
  15. {
  16. BitmapManager bitmapManager = new BitmapManager();
  17. bitmapManager.SetActiveTool(new MockedSinglePixelPenTool());
  18. Assert.Equal(typeof(MockedSinglePixelPenTool), bitmapManager.SelectedTool.GetType());
  19. }
  20. [Fact]
  21. public void TestThatBitmapManagerAddsEmptyNewLayer()
  22. {
  23. string layerName = "TestLayer";
  24. BitmapManager bitmapManager = new BitmapManager
  25. {
  26. ActiveDocument = new Document(10, 10)
  27. };
  28. bitmapManager.ActiveDocument.AddNewLayer(layerName);
  29. Assert.Single(bitmapManager.ActiveDocument.Layers);
  30. Assert.Equal(layerName, bitmapManager.ActiveDocument.ActiveLayer.Name);
  31. Assert.Equal(0, bitmapManager.ActiveDocument.ActiveLayer.Width + bitmapManager.ActiveDocument.ActiveLayer.Height);
  32. }
  33. [Fact]
  34. public void TestThatBitmapManagerRemovesLayer()
  35. {
  36. BitmapManager bitmapManager = new BitmapManager
  37. {
  38. ActiveDocument = new Document(10, 10)
  39. };
  40. bitmapManager.ActiveDocument.AddNewLayer("_");
  41. bitmapManager.ActiveDocument.AddNewLayer("_1");
  42. Assert.Equal(2, bitmapManager.ActiveDocument.Layers.Count);
  43. bitmapManager.ActiveDocument.RemoveLayer(0);
  44. Assert.Single(bitmapManager.ActiveDocument.Layers);
  45. }
  46. [Fact]
  47. public void TestThatGeneratePreviewLayerGeneratesPreviewLayer()
  48. {
  49. BitmapManager bitmapManager = new BitmapManager
  50. {
  51. ActiveDocument = new Document(10, 10)
  52. };
  53. bitmapManager.ActiveDocument.GeneratePreviewLayer();
  54. Assert.NotNull(bitmapManager.ActiveDocument.PreviewLayer);
  55. Assert.Equal(0, bitmapManager.ActiveDocument.PreviewLayer.Width + bitmapManager.ActiveDocument.PreviewLayer.Height); // Size is zero
  56. Assert.Equal(0, bitmapManager.ActiveDocument.PreviewLayer.OffsetX + bitmapManager.ActiveDocument.PreviewLayer.OffsetY); // Offset is zero
  57. Assert.Equal(bitmapManager.ActiveDocument.Width, bitmapManager.ActiveDocument.PreviewLayer.MaxWidth);
  58. Assert.Equal(bitmapManager.ActiveDocument.Height, bitmapManager.ActiveDocument.PreviewLayer.MaxHeight);
  59. }
  60. [Fact]
  61. public void TestThatIsOperationToolWorks()
  62. {
  63. MockedSinglePixelPenTool singlePixelPen = new MockedSinglePixelPenTool();
  64. Assert.True(BitmapManager.IsOperationTool(singlePixelPen));
  65. }
  66. [StaFact]
  67. public void TestThatBitmapChangesExecuteToolExecutesPenTool()
  68. {
  69. BitmapManager bitmapManager = new BitmapManager
  70. {
  71. Documents = new System.Collections.ObjectModel.ObservableCollection<Document>()
  72. {
  73. new Document(5, 5)
  74. }
  75. };
  76. bitmapManager.ActiveDocument = bitmapManager.Documents[0];
  77. bitmapManager.ActiveDocument.AddNewLayer("Layer");
  78. bitmapManager.SetActiveTool(new MockedSinglePixelPenTool());
  79. bitmapManager.PrimaryColor = ExtendedColorTests.black;
  80. bitmapManager.MouseController.StartRecordingMouseMovementChanges(true);
  81. bitmapManager.MouseController.RecordMouseMovementChange(new Coordinates(1, 1));
  82. bitmapManager.MouseController.StopRecordingMouseMovementChanges();
  83. bitmapManager.ExecuteTool(new Coordinates(1, 1), true);
  84. Assert.Equal(ExtendedColorTests.black, bitmapManager.ActiveLayer.GetPixelWithOffset(1, 1));
  85. }
  86. }
  87. }