Browse Source

FIx control leak tests.

Steven Kirk 9 years ago
parent
commit
00f3ca78ba
1 changed files with 13 additions and 12 deletions
  1. 13 12
      tests/Avalonia.LeakTests/ControlTests.cs

+ 13 - 12
tests/Avalonia.LeakTests/ControlTests.cs

@@ -11,9 +11,11 @@ using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Templates;
 using Avalonia.Diagnostics;
 using Avalonia.Layout;
+using Avalonia.Rendering;
 using Avalonia.Styling;
 using Avalonia.UnitTests;
 using Avalonia.VisualTree;
+using Moq;
 using Xunit;
 using Xunit.Abstractions;
 
@@ -52,6 +54,7 @@ namespace Avalonia.LeakTests
                 };
 
                 var result = run();
+                PurgeMoqReferences();
 
                 dotMemory.Check(memory =>
                     Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Canvas>()).ObjectsCount));
@@ -87,6 +90,7 @@ namespace Avalonia.LeakTests
                 };
 
                 var result = run();
+                PurgeMoqReferences();
 
                 dotMemory.Check(memory =>
                     Assert.Equal(0, memory.GetObjects(where => where.Type.Is<Canvas>()).ObjectsCount));
@@ -123,6 +127,7 @@ namespace Avalonia.LeakTests
                 };
 
                 var result = run();
+                PurgeMoqReferences();
 
                 dotMemory.Check(memory =>
                     Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount));
@@ -158,6 +163,7 @@ namespace Avalonia.LeakTests
                 };
 
                 var result = run();
+                PurgeMoqReferences();
 
                 dotMemory.Check(memory =>
                     Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount));
@@ -201,6 +207,7 @@ namespace Avalonia.LeakTests
                 };
 
                 var result = run();
+                PurgeMoqReferences();
 
                 dotMemory.Check(memory =>
                     Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TextBox>()).ObjectsCount));
@@ -287,25 +294,19 @@ namespace Avalonia.LeakTests
                 };
 
                 var result = run();
+                PurgeMoqReferences();
 
                 dotMemory.Check(memory =>
                     Assert.Equal(0, memory.GetObjects(where => where.Type.Is<TreeView>()).ObjectsCount));
             }
         }
 
-        private class TestTemplatedControl : TemplatedControl
+        private static void PurgeMoqReferences()
         {
-            public static readonly StyledProperty<int> IsCanvasVisibleProperty =
-                AvaloniaProperty.Register<TestTemplatedControl, int>("IsCanvasVisible");
-
-            public TestTemplatedControl()
-            {
-                Template = new FuncControlTemplate<TestTemplatedControl>(parent =>
-                    new Canvas
-                    {
-                        [~IsVisibleProperty] = parent[~IsCanvasVisibleProperty]
-                    });
-            }
+            // Moq holds onto references in its mock of IRenderer in case we want to check if a method has been called;
+            // clear these.
+            var renderer = Mock.Get(AvaloniaLocator.Current.GetService<IRenderer>());
+            renderer.ResetCalls();
         }
 
         private class Node