/
BackgroundColorTests.cs
86 lines (77 loc) · 2.7 KB
/
BackgroundColorTests.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
using System.Collections;
using System.Linq;
using System.Threading.Tasks;
using Android.Graphics.Drawables;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;
namespace Xamarin.Forms.Platform.Android.UnitTests
{
[TestFixture]
public class BackgroundColorTests : PlatformTestFixture
{
static IEnumerable TestCases
{
get
{
foreach (var element in BasicElements
.Where(e => !(e is Button) && !(e is ImageButton) && !(e is Frame)))
{
element.BackgroundColor = Color.AliceBlue;
yield return new TestCaseData(element)
.SetCategory(element.GetType().Name);
}
}
}
[Test, Category("BackgroundColor"), Category("Button")]
[Description("Button background color should match renderer background color")]
public async Task ButtonBackgroundColorConsistent()
{
var button = new Button
{
Text = " ",
HeightRequest = 100, WidthRequest = 100,
BackgroundColor = Color.AliceBlue
};
var expectedColor = button.BackgroundColor.ToAndroid();
var screenshot = await GetControlProperty(button, abutton => abutton.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}
[Test, Category("BackgroundColor"), Category("Button")]
[Description("ImageButton background color should match renderer background color")]
public async Task ImageButtonBackgroundColorConsistent()
{
var button = new ImageButton
{
HeightRequest = 100,
WidthRequest = 100,
BackgroundColor = Color.AliceBlue
};
var expectedColor = button.BackgroundColor.ToAndroid();
var screenshot = await GetControlProperty(button, abutton => abutton.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}
[Test, Category("BackgroundColor")]
[Description("Frame background color should match renderer background color")]
public async Task FrameBackgroundColorConsistent()
{
var frame = new Frame
{
HeightRequest = 100,
WidthRequest = 100,
BackgroundColor = Color.AliceBlue
};
var expectedColor = frame.BackgroundColor.ToAndroid();
var screenshot = await GetRendererProperty(frame, ver => ver.View.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}
[Test, Category("BackgroundColor"), TestCaseSource(nameof(TestCases))]
[Description("VisualElement background color should match renderer background color")]
public async Task BackgroundColorConsistent(VisualElement element)
{
var expectedColor = element.BackgroundColor.ToAndroid();
var nativeColor = await GetRendererProperty(element, ver => (ver.View.Background as ColorDrawable)?.Color);
Assert.That(nativeColor, Is.EqualTo(expectedColor));
}
}
}