-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
IsEnabledTests.cs
58 lines (52 loc) · 1.53 KB
/
IsEnabledTests.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
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Xamarin.Forms.Platform.UAP.UnitTests
{
[TestFixture]
public class IsEnabledTests : PlatformTestFixture
{
static IEnumerable TestCases
{
get
{
// Generate IsEnabled = true cases
foreach (var element in BasicViews)
{
element.IsEnabled = true;
yield return CreateTestCase(element)
.SetName($"{element.GetType().Name}_IsEnabled_{element.IsEnabled}");
}
// Generate IsEnabled = false cases
foreach (var element in BasicViews)
{
element.IsEnabled = false;
yield return CreateTestCase(element)
.SetName($"{element.GetType().Name}_IsEnabled_{element.IsEnabled}");
}
}
}
[Test, Category("IsEnabled"), TestCaseSource(nameof(TestCases))]
[Description("View enabled should match renderer enabled")]
public async Task EnabledConsistent(VisualElement element)
{
await Device.InvokeOnMainThreadAsync(() =>
{
using (var renderer = GetRenderer(element))
{
var expected = element.IsEnabled;
var container = renderer.ContainerElement;
// Check the container control
Assert.That(container.IsHitTestVisible, Is.EqualTo(expected));
// Check the actual control (if there is one; for some renderers, like Frame and BoxView, the
// native control isn't a Windows.UI.Xaml.Controls.Control)
var control = GetNativeControl(element);
if (control != null)
{
Assert.That(control.IsEnabled, Is.EqualTo(expected));
}
}
});
}
}
}