Browse Source

Fix warnings in tests

Equbuxu 3 years ago
parent
commit
79c04059f2

+ 5 - 5
PixiEditorTests/ModelsTests/ControllersTests/MockedSinglePixelPenTool.cs

@@ -1,10 +1,9 @@
-using System.Collections.Generic;
-using System.Windows.Media;
-using PixiEditor.Models.DataHolders;
-using PixiEditor.Models.Layers;
+using PixiEditor.Models.Layers;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
 using SkiaSharp;
+using System;
+using System.Collections.Generic;
 
 namespace PixiEditorTests.ModelsTests.ControllersTests
 {
@@ -15,8 +14,9 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public override void Use(Layer activeLayer, Layer previewLayer, IEnumerable<Layer> allLayers, IReadOnlyList<Coordinates> recordedMouseMovement,
             SKColor color)
         {
+            if (recordedMouseMovement == null || activeLayer == null)
+                throw new ArgumentException("Parameter is null");
             activeLayer.LayerBitmap.SkiaSurface.Canvas.DrawPoint(recordedMouseMovement[0].ToSKPoint(), color);
-
         }
     }
 }

+ 40 - 32
PixiEditorTests/ModelsTests/ControllersTests/UndoManagerTests.cs

@@ -1,5 +1,4 @@
 using PixiEditor.Models.Controllers;
-using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.Undo;
 using Xunit;
 
@@ -20,7 +19,7 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestSetRoot()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
             Assert.Equal(this, undoManager.MainRoot);
         }
 
@@ -28,9 +27,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestAddToUndoStack()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
+            using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
+            undoManager.AddUndoChange(change);
             Assert.True(undoManager.UndoStack.Count == 1);
             Assert.True((int)undoManager.UndoStack.Peek().OldValue == ExampleProperty);
         }
@@ -39,9 +39,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatUndoAddsToRedoStack()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
+            using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
+            undoManager.AddUndoChange(change);
             undoManager.Undo();
             Assert.True(undoManager.RedoStack.Count == 1);
         }
@@ -50,9 +51,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestUndo()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, 55));
+            using var change = new Change("ExampleProperty", ExampleProperty, 55);
+            undoManager.AddUndoChange(change);
             ExampleProperty = 55;
             undoManager.Undo();
             Assert.True((int)undoManager.RedoStack.Peek().OldValue == ExampleProperty);
@@ -62,9 +64,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatRedoAddsToUndoStack()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("ExampleProperty", ExampleProperty, ExampleProperty));
+            using var change = new Change("ExampleProperty", ExampleProperty, ExampleProperty);
+            undoManager.AddUndoChange(change);
             undoManager.Undo();
             undoManager.Redo();
             Assert.True(undoManager.UndoStack.Count == 1);
@@ -74,10 +77,11 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestRedo()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
             ExampleProperty = 55;
-            undoManager.AddUndoChange(new Change("ExampleProperty", 1, ExampleProperty));
+            using var change = new Change("ExampleProperty", 1, ExampleProperty);
+            undoManager.AddUndoChange(change);
             undoManager.Undo();
             undoManager.Redo();
             Assert.True((int)undoManager.UndoStack.Peek().NewValue == ExampleProperty);
@@ -87,12 +91,13 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatUndoManagerUndoAndRedoWithCustomRootCorrectly()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
             TestPropertyClass testProp = new TestPropertyClass();
             int newVal = 5;
             testProp.IntProperty = newVal;
-            undoManager.AddUndoChange(new Change("IntProperty", 0, newVal, root: testProp));
+            using var change = new Change("IntProperty", 0, newVal, root: testProp);
+            undoManager.AddUndoChange(change);
             Assert.Equal(newVal, testProp.IntProperty);
 
             undoManager.Undo();
@@ -108,16 +113,15 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatMixedProcessOfUndoAndRedoWorks()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
             int newVal = 5;
-
-            undoManager.AddUndoChange(
-                new Change(
+            using var change = new Change(
                     "ExampleProperty",
                     ReverseProcess,
                     new object[] { ExampleProperty },
-                    newVal));
+                    newVal);
+            undoManager.AddUndoChange(change);
 
             ExampleProperty = newVal;
 
@@ -136,14 +140,15 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatProcessBasedUndoAndRedoWorks()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
             int newVal = 5;
-            undoManager.AddUndoChange(new Change(
+            using var change = new Change(
                 ReverseProcess,
                 new object[] { ExampleProperty },
                 ReverseProcess,
-                new object[] { newVal }));
+                new object[] { newVal });
+            undoManager.AddUndoChange(change);
 
             ExampleProperty = newVal;
 
@@ -162,11 +167,11 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatNestedPropertyUndoWorks()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
             int newVal = 5;
-
-            undoManager.AddUndoChange(new Change("TestPropClass.IntProperty", TestPropClass.IntProperty, newVal));
+            using var change = new Change("TestPropClass.IntProperty", TestPropClass.IntProperty, newVal);
+            undoManager.AddUndoChange(change);
 
             TestPropClass.IntProperty = newVal;
 
@@ -185,9 +190,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatFindRootProcessWorks()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));
+            using var change1 = new Change("IntProperty", 0, 5, FindRootProcess, null);
+            undoManager.AddUndoChange(change1);
 
             Change change = undoManager.UndoStack.Peek();
 
@@ -198,9 +204,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatUndoForFindRootProcessWorks()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));
+            using var change = new Change("IntProperty", 0, 5, FindRootProcess, null);
+            undoManager.AddUndoChange(change);
 
             TestPropClass.IntProperty = 5;
 
@@ -213,9 +220,10 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
         public void TestThatUndoAndRedoForFindRootProcessWorks()
         {
             PrepareUndoManagerForTest();
-            UndoManager undoManager = new UndoManager(this);
+            using UndoManager undoManager = new UndoManager(this);
 
-            undoManager.AddUndoChange(new Change("IntProperty", 0, 5, FindRootProcess, null));
+            using var change = new Change("IntProperty", 0, 5, FindRootProcess, null);
+            undoManager.AddUndoChange(change);
 
             TestPropClass.IntProperty = 5;
 
@@ -244,4 +252,4 @@ namespace PixiEditorTests.ModelsTests.ControllersTests
             TestPropClass = new TestPropertyClass { IntProperty = 0 };
         }
     }
-}
+}

+ 12 - 13
PixiEditorTests/ModelsTests/DataHoldersTests/DocumentLayersTests.cs

@@ -1,6 +1,5 @@
-using System;
-using PixiEditor.Models.DataHolders;
-using PixiEditor.ViewModels.SubViewModels.Main;
+using PixiEditor.Models.DataHolders;
+using System;
 using Xunit;
 
 namespace PixiEditorTests.ModelsTests.DataHoldersTests
@@ -11,7 +10,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatToggleLayerDoesNotToggleLastLayer()
         {
-            Document doc = new (5, 5);
+            using Document doc = new(5, 5);
             doc.AddNewLayer("layer");
             bool isActive = doc.Layers[^1].IsActive;
             doc.ToggleLayer(0);
@@ -21,7 +20,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatToggleLayerTogglesLayer()
         {
-            Document doc = new (5, 5);
+            using Document doc = new(5, 5);
             doc.AddNewLayer("layer");
             doc.AddNewLayer("layer 1");
             doc.Layers[0].IsActive = true;
@@ -35,7 +34,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatToggleLayerDoesNothingOnNonExistingIndex()
         {
-            Document document = new Document(5, 5);
+            using Document document = new Document(5, 5);
             document.AddNewLayer("test");
             document.ToggleLayer(1);
             document.ToggleLayer(-1);
@@ -48,7 +47,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [InlineData(1, 1)]
         public void TestThatSelectLayersRangeSelectsRange(int startIndex, int endIndex)
         {
-            Document document = new Document(5, 5);
+            using Document document = new Document(5, 5);
 
             document.AddNewLayer("1");
             document.AddNewLayer("2");
@@ -62,7 +61,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
             {
                 Assert.Equal(
                     i >= Math.Min(startIndex, endIndex)
-                    && i <= Math.Max(startIndex, endIndex), 
+                    && i <= Math.Max(startIndex, endIndex),
                     document.Layers[i].IsActive);
             }
         }
@@ -73,7 +72,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [InlineData(2)]
         public void TestThatDeselectAllExceptDeselectsAllExceptLayer(int index)
         {
-            Document document = new Document(5, 5);
+            using Document document = new Document(5, 5);
 
             document.AddNewLayer("1");
             document.AddNewLayer("2");
@@ -94,7 +93,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatUpdateLayersColorMakesOnlyOneLayerMainColorAndOtherSecondary()
         {
-            Document document = new Document(1, 1);
+            using Document document = new Document(1, 1);
 
             document.AddNewLayer("1");
             document.AddNewLayer("2");
@@ -114,7 +113,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatUpdateLayersColorMakesLayerMainColorAndRestNonActiveReturnsTransparent()
         {
-            Document document = new Document(1, 1);
+            using Document document = new Document(1, 1);
 
             document.AddNewLayer("1");
             document.AddNewLayer("2");
@@ -134,7 +133,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatSetNextSelectedLayerAsActiveSelectsFirstAvailableLayer()
         {
-            Document document = new Document(1, 1);
+            using Document document = new Document(1, 1);
 
             document.AddNewLayer("1");
             document.AddNewLayer("2");
@@ -151,4 +150,4 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
             Assert.Equal(document.Layers[0].GuidValue, document.ActiveLayerGuid);
         }
     }
-}
+}

+ 16 - 15
PixiEditorTests/ModelsTests/DataHoldersTests/LayerStructureTests.cs

@@ -10,7 +10,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatAddNewGroupAddsNewGroup()
         {
-            Document doc = new Document(1, 1);
+            using Document doc = new Document(1, 1);
             doc.Layers.Add(new("_testLayer", 1, 1));
             var testLayer = doc.Layers[^1];
             doc.LayerStructure.AddNewGroup("test", testLayer.GuidValue);
@@ -23,7 +23,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatAddNewGroupAddsNewGroupAsASubgroup()
         {
-            Document doc = new Document(1, 1);
+            using Document doc = new Document(1, 1);
             doc.Layers.Add(new("_testLayer", 1, 1));
             var testLayer = doc.Layers[^1];
             doc.LayerStructure.AddNewGroup("test", testLayer.GuidValue);
@@ -40,7 +40,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatMoveGroupMovesSwapsLayerPlacesWithOtherGroup()
         {
-            Document doc = new Document(1, 1);
+            using Document doc = new Document(1, 1);
             doc.Layers.Add(new Layer("_testLayer", 1, 1));
             doc.Layers.Add(new Layer("_testLayer1", 1, 1));
             var testLayer = doc.Layers[0];
@@ -60,7 +60,8 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatIsChildOfDetectsNestedGroupCorrectly()
         {
-            LayerStructure ls = new LayerStructure(new Document(1, 1));
+            using var doc = new Document(1, 1);
+            LayerStructure ls = new LayerStructure(doc);
             Layer testLayer = new Layer("tst", 1, 1);
             ls.Groups.Add(new GuidStructureItem("group 1", testLayer.GuidValue));
             ls.Groups[0].Subgroups.Add(new GuidStructureItem("group 1 nested", testLayer.GuidValue));
@@ -72,7 +73,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatIsChildOfDetectsNestedLayersCorrectly()
         {
-            var doc = new Document(1, 1);
+            using var doc = new Document(1, 1);
             doc.Layers.Add(new Layer("tst", 1, 1));
             Guid testLayerGuid = doc.Layers[0].GuidValue;
             LayerStructure ls = new LayerStructure(doc);
@@ -86,7 +87,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatGroupContainsOnlyLayerDetectsOnlySingleLayerCorrectly()
         {
-            var doc = new Document(1, 1);
+            using var doc = new Document(1, 1);
             doc.Layers.Add(new Layer("layer", 1, 1));
             var guid = doc.Layers[0].GuidValue;
             doc.LayerStructure.AddNewGroup("layer group", guid);
@@ -96,7 +97,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatGroupContainsOnlyLayerDetectsOnlySingleLayerThatIsNested()
         {
-            var doc = new Document(1, 1);
+            using var doc = new Document(1, 1);
             doc.Layers.Add(new Layer("layer", 1, 1));
             var guid = doc.Layers[0].GuidValue;
             doc.LayerStructure.AddNewGroup("layer group", guid);
@@ -108,7 +109,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatCloneReturnsSameLayerStructure()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new("Test", 1, 1));
             doc.Layers.Add(new("Test2", 1, 1));
             LayerStructure structure = new(doc);
@@ -124,7 +125,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatGetGroupByGuidReturnsNullForNonExistingGroup()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new("Test", 1, 1));
 
             Assert.Null(doc.LayerStructure.GetGroupByGuid(null));
@@ -134,7 +135,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatGetGroupByGuidReturnsGroupCorrectly()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new("Test", 1, 1));
             var group = doc.LayerStructure.AddNewGroup("Test group", doc.Layers[0].GuidValue);
 
@@ -144,7 +145,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatPreMoveReassignBoundsMakesNestedGroupEmptyAndRemovesItAndParent()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new("Test", 1, 1));
             doc.LayerStructure.AddNewGroup("Test group", doc.Layers[0].GuidValue);
             var group1 = doc.LayerStructure.AddNewGroup("Test group nested", doc.Layers[0].GuidValue);
@@ -157,7 +158,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatPostMoveReassignBoundsAssignsNewLayerToGroup()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new("Test", 1, 1));
             doc.LayerStructure.AddNewGroup("Test group", doc.Layers[0].GuidValue);
             var group1 = doc.LayerStructure.AddNewGroup("Test group nested", doc.Layers[0].GuidValue);
@@ -180,7 +181,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatAssignParentAssignsParent()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new Layer("Test", 1, 1));
 
             var firstLayer = doc.Layers[0];
@@ -200,7 +201,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatAssignParentDeAssignsParentOnNull()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new Layer("Test", 1, 1));
 
             var firstLayer = doc.Layers[0];
@@ -221,7 +222,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatGetGroupLayersReturnsAllLayersInGroup()
         {
-            Document doc = new(1, 1);
+            using Document doc = new(1, 1);
             doc.Layers.Add(new Layer("Test", 1, 1));
             doc.Layers.Add(new Layer("Test 1", 1, 1));
             doc.Layers.Add(new Layer("Test 2", 1, 1));

+ 2 - 2
PixiEditorTests/ModelsTests/DataHoldersTests/SelectionTests.cs

@@ -13,7 +13,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatSetSelectionNewSetsCorrectSelection()
         {
-            Selection selection = new Selection(Array.Empty<Coordinates>(), new (10, 10));
+            Selection selection = new Selection(Array.Empty<Coordinates>(), new(10, 10));
             Coordinates[] points = { new Coordinates(0, 0), new Coordinates(1, 1) };
 
             selection.SetSelection(points, SelectionType.New);
@@ -62,7 +62,7 @@ namespace PixiEditorTests.ModelsTests.DataHoldersTests
         [Fact]
         public void TestThatUndoWorks()
         {
-            Document document = new Document(10, 10);
+            using Document document = new Document(10, 10);
 
             IEnumerable<Coordinates> oldSelection = new List<Coordinates>(document.ActiveSelection.SelectedPoints);
 

+ 2 - 0
PixiEditorTests/ModelsTests/DataHoldersTests/SurfaceTests.cs

@@ -4,7 +4,9 @@ using Xunit;
 
 namespace PixiEditorTests.ModelsTests.DataHoldersTests
 {
+#pragma warning disable CA1001 // Types that own disposable fields should be disposable
     public class SurfaceTests
+#pragma warning restore CA1001 // Types that own disposable fields should be disposable
     {
         SKColor redColor = new SKColor(254, 2, 3);
         SKColor greenColor = new SKColor(6, 224, 3);

+ 5 - 1
PixiEditorTests/ModelsTests/LayersTests/LayersTestHelper.cs

@@ -7,6 +7,9 @@ namespace PixiEditorTests.ModelsTests.LayersTests
     {
         public static void LayersAreEqual(Layer expected, Layer actual)
         {
+            Assert.NotNull(actual);
+            Assert.NotNull(expected);
+#pragma warning disable CA1062 // Validate arguments of public methods
             Assert.Equal(expected.Name, actual.Name);
             Assert.Equal(expected.Offset, actual.Offset);
             Assert.Equal(expected.Width, actual.Width);
@@ -17,6 +20,7 @@ namespace PixiEditorTests.ModelsTests.LayersTests
             Assert.Equal(expected.IsVisible, actual.IsVisible);
             Assert.Equal(expected.IsRenaming, actual.IsRenaming);
             Assert.Equal(expected.ConvertBitmapToBytes(), actual.ConvertBitmapToBytes());
+#pragma warning restore CA1062 // Validate arguments of public methods
         }
     }
-}
+}

+ 3 - 2
PixiEditorTests/ModelsTests/PositionTests/CoordinatesTests.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Models.Position;
+using System.Globalization;
 using Xunit;
 
 namespace PixiEditorTests.ModelsTests.PositionTests
@@ -10,7 +11,7 @@ namespace PixiEditorTests.ModelsTests.PositionTests
         {
             Coordinates cords = new Coordinates(5, 5);
 
-            Assert.Equal("5, 5", cords.ToString());
+            Assert.Equal("5, 5", cords.ToString(CultureInfo.InvariantCulture));
         }
 
         [Fact]
@@ -22,4 +23,4 @@ namespace PixiEditorTests.ModelsTests.PositionTests
             Assert.True(cords != cords2);
         }
     }
-}
+}

+ 16 - 17
PixiEditorTests/ModelsTests/UndoTests/StorageBasedChangeTests.cs

@@ -5,7 +5,6 @@ using PixiEditor.Models.Undo;
 using PixiEditorTests.ModelsTests.LayersTests;
 using SkiaSharp;
 using System;
-using System.Collections.ObjectModel;
 using System.IO;
 using Xunit;
 
@@ -23,11 +22,11 @@ namespace PixiEditorTests.ModelsTests.UndoTests
             }
         }
 
-        public Document GenerateTestDocument()
+        public static Document GenerateTestDocument()
         {
-            Document testDocument = new Document(10, 10);
-            Surface testBitmap = new Surface(10, 10);
-            Surface testBitmap2 = new Surface(5, 8);
+            using Document testDocument = new Document(10, 10);
+            using Surface testBitmap = new Surface(10, 10);
+            using Surface testBitmap2 = new Surface(5, 8);
             testBitmap.SetSRGBPixel(0, 0, SKColors.Black);
             testBitmap2.SetSRGBPixel(4, 4, SKColors.Blue);
             Random random = new Random();
@@ -42,9 +41,9 @@ namespace PixiEditorTests.ModelsTests.UndoTests
         [Fact]
         public void TestThatConstructorGeneratesUndoLayersProperly()
         {
-            Document testDocument = GenerateTestDocument();
+            using Document testDocument = GenerateTestDocument();
 
-            StorageBasedChange change = new StorageBasedChange(testDocument, testDocument.Layers, UndoStoreLocation);
+            using StorageBasedChange change = new StorageBasedChange(testDocument, testDocument.Layers, UndoStoreLocation);
 
             Assert.Equal(testDocument.Layers.Count, change.StoredLayers.Length);
 
@@ -69,9 +68,9 @@ namespace PixiEditorTests.ModelsTests.UndoTests
         [Fact]
         public void TestThatSaveLayersOnDeviceSavesLayers()
         {
-            Document document = GenerateTestDocument();
+            using Document document = GenerateTestDocument();
 
-            StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
+            using StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
 
             foreach (var layer in change.StoredLayers)
             {
@@ -83,9 +82,9 @@ namespace PixiEditorTests.ModelsTests.UndoTests
         [Fact]
         public void TestThatLoadLayersFromDeviceLoadsLayers()
         {
-            Document document = GenerateTestDocument();
+            using Document document = GenerateTestDocument();
 
-            StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
+            using StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
 
             Layer[] layers = change.LoadLayersFromDevice();
 
@@ -101,9 +100,9 @@ namespace PixiEditorTests.ModelsTests.UndoTests
         [Fact]
         public void TestThatUndoInvokesLoadFromDeviceAndExecutesProcess()
         {
-            Document document = GenerateTestDocument();
+            using Document document = GenerateTestDocument();
 
-            StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
+            using StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
             bool undoInvoked = false;
 
             Action<Layer[], UndoLayer[]> testUndoProcess = (layers, data) =>
@@ -120,7 +119,7 @@ namespace PixiEditorTests.ModelsTests.UndoTests
             Action<object[]> testRedoProcess = parameters => { };
 
             Change undoChange = change.ToChange(testUndoProcess, testRedoProcess, null);
-            UndoManager manager = new UndoManager(this);
+            using UndoManager manager = new UndoManager(this);
 
             manager.AddUndoChange(undoChange);
             manager.Undo();
@@ -131,9 +130,9 @@ namespace PixiEditorTests.ModelsTests.UndoTests
         [Fact]
         public void TestThatRedoInvokesSaveToDeviceAndExecutesProcess()
         {
-            Document document = GenerateTestDocument();
+            using Document document = GenerateTestDocument();
 
-            StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
+            using StorageBasedChange change = new StorageBasedChange(document, document.Layers, UndoStoreLocation);
             bool redoInvoked = false;
 
             Action<Layer[], UndoLayer[]> testUndoProcess = (layers, data) => { };
@@ -152,7 +151,7 @@ namespace PixiEditorTests.ModelsTests.UndoTests
             };
 
             Change undoChange = change.ToChange(testUndoProcess, testRedoProcess, new object[] { 2 });
-            UndoManager manager = new UndoManager(this);
+            using UndoManager manager = new UndoManager(this);
 
             manager.AddUndoChange(undoChange);
             manager.Undo();