Browse Source

FIx control leak tests.

pull/773/head
Steven Kirk 10 years ago
parent
commit
00f3ca78ba
  1. 25
      tests/Avalonia.LeakTests/ControlTests.cs

25
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

Loading…
Cancel
Save