/
BoxViewTests.iOS.cs
50 lines (43 loc) · 1.28 KB
/
BoxViewTests.iOS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Graphics.Platform;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Microsoft.Maui.Controls;
using System.Reflection;
using Xunit;
namespace Microsoft.Maui.DeviceTests
{
public partial class BoxViewTests
{
MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewHandler) =>
boxViewHandler.PlatformView;
[Fact(DisplayName = "ShapeView Parts Keep Around")]
public async Task ShapeViewPartsKeepAround()
{
var boxView = new BoxView()
{
HeightRequest = 100,
WidthRequest = 200
};
await AttachAndRun<ShapeViewHandler>(boxView, async handler =>
{
var shapeView = GetNativeBoxView(handler);
var renderer = (DirectRenderer)shapeView.Renderer;
GC.Collect();
GC.WaitForPendingFinalizers();
await Task.Yield();
GC.Collect();
GC.WaitForPendingFinalizers();
await Task.Yield();
Assert.NotNull(shapeView.Renderer);
Assert.NotNull(shapeView.Drawable);
Assert.NotNull(renderer.Drawable);
var flags = BindingFlags.NonPublic | BindingFlags.Instance;
var graphicsView = renderer.GetType().GetField("_graphicsView", flags)?.GetValue(renderer) as PlatformGraphicsView;
Assert.NotNull(graphicsView);
});
}
}
}