BitmapManagerTests.cs 3.9 KB

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