/
CornerRadiusTests.cs
102 lines (86 loc) · 2.34 KB
/
CornerRadiusTests.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Platform.Android;
namespace Xamarin.Forms.Platform.Android.UnitTests
{
[TestFixture]
public class CornerRadiusTests : PlatformTestFixture
{
[Test, Category("CornerRadius"), Category("BoxView")]
public async Task BoxviewCornerRadius()
{
var boxView = new BoxView
{
HeightRequest = 100,
WidthRequest = 200,
CornerRadius = 15,
BackgroundColor = Color.Red
};
await CheckCornerRadius(boxView);
}
[Test, Category("CornerRadius"), Category("Button")]
public async Task ButtonCornerRadius()
{
var backgroundColor = Color.Red;
var button = new Button
{
HeightRequest = 100,
WidthRequest = 200,
CornerRadius = 15,
BackgroundColor = backgroundColor
};
await CheckCornerRadius(button);
}
[Test, Category("CornerRadius"), Category("Frame")]
public async Task FrameCornerRadius()
{
var backgroundColor = Color.Red;
var frame = new Frame
{
HeightRequest = 100,
WidthRequest = 200,
CornerRadius = 15,
BackgroundColor = backgroundColor
};
await CheckCornerRadius(frame);
}
[Test, Category("CornerRadius"), Category("ImageButton")]
public async Task ImageButtonCornerRadius()
{
var backgroundColor = Color.Red;
var button = new ImageButton
{
HeightRequest = 100,
WidthRequest = 200,
CornerRadius = 15,
BackgroundColor = backgroundColor,
BorderColor = Color.Black,
BorderWidth = 2
};
await CheckCornerRadius(button);
}
public async Task CheckCornerRadius(VisualElement visualElement)
{
var screenshot = await Device.InvokeOnMainThreadAsync(() => {
using (var renderer = GetRenderer(visualElement))
{
var view = renderer.View;
Layout(visualElement, view);
// Need to parent the Frame for it to work on lower APIs (below Marshmallow)
ParentView(view);
var image = view.ToBitmap();
UnparentView(view);
return image;
}
});
// The corners should show the background color
screenshot.AssertColorAtTopLeft(EmptyBackground)
.AssertColorAtTopRight(EmptyBackground)
.AssertColorAtBottomLeft(EmptyBackground)
.AssertColorAtBottomRight(EmptyBackground)
.AssertColorAtCenter(visualElement.BackgroundColor.ToAndroid());
}
}
}