BitmapManagerTests.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 Xunit;
  14. namespace PixiEditorTests.ModelsTests.ControllersTests
  15. {
  16. public class BitmapManagerTests
  17. {
  18. [Fact]
  19. public void TestThatBitmapManagerSetsCorrectTool()
  20. {
  21. BitmapManager bitmapManager = new BitmapManager();
  22. bitmapManager.SetActiveTool(new MockedPen());
  23. Assert.Equal(ToolType.Pen, bitmapManager.SelectedTool.ToolType);
  24. }
  25. [Fact]
  26. public void TestThatBitmapManagerAddsEmptyNewLayer()
  27. {
  28. string layerName = "TestLayer";
  29. BitmapManager bitmapManager = new BitmapManager
  30. {
  31. ActiveDocument = new Document(10, 10)
  32. };
  33. bitmapManager.AddNewLayer(layerName);
  34. Assert.Single(bitmapManager.ActiveDocument.Layers);
  35. Assert.Equal(layerName, bitmapManager.ActiveDocument.ActiveLayer.Name);
  36. Assert.Equal(0, bitmapManager.ActiveDocument.ActiveLayer.Width + bitmapManager.ActiveDocument.ActiveLayer.Height);
  37. }
  38. [Fact]
  39. public void TestThatBitmapManagerRemovesLayer()
  40. {
  41. BitmapManager bitmapManager = new BitmapManager
  42. {
  43. ActiveDocument = new Document(10, 10)
  44. };
  45. bitmapManager.AddNewLayer("_");
  46. bitmapManager.AddNewLayer("_1");
  47. Assert.Equal(2,bitmapManager.ActiveDocument.Layers.Count);
  48. bitmapManager.RemoveLayer(0);
  49. Assert.Single(bitmapManager.ActiveDocument.Layers);
  50. }
  51. [Fact]
  52. public void TestThatGeneratePreviewLayerGeneratesPreviewLayer()
  53. {
  54. BitmapManager bitmapManager = new BitmapManager
  55. {
  56. ActiveDocument = new Document(10, 10)
  57. };
  58. bitmapManager.GeneratePreviewLayer();
  59. Assert.NotNull(bitmapManager.PreviewLayer);
  60. Assert.Equal(0, bitmapManager.PreviewLayer.Width + bitmapManager.PreviewLayer.Height); //Size is zero
  61. Assert.Equal(0, bitmapManager.PreviewLayer.OffsetX + bitmapManager.PreviewLayer.OffsetY); //Offset is zero
  62. Assert.Equal(bitmapManager.ActiveDocument.Width,bitmapManager.PreviewLayer.MaxWidth);
  63. Assert.Equal(bitmapManager.ActiveDocument.Height,bitmapManager.PreviewLayer.MaxHeight);
  64. }
  65. [Fact]
  66. public void TestThatIsOperationToolWorks()
  67. {
  68. MockedPen pen = new MockedPen();
  69. Assert.True(BitmapManager.IsOperationTool(pen));
  70. }
  71. }
  72. public class MockedPen : BitmapOperationTool
  73. {
  74. public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color color)
  75. {
  76. PenTool pen = new PenTool()
  77. {
  78. Toolbar = null
  79. };
  80. return pen.Use(layer, mouseMove, color);
  81. }
  82. public override ToolType ToolType { get; } = ToolType.Pen;
  83. }
  84. }