BitmapManagerTests.cs 3.9 KB

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