-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
IsEnabledTests.cs
58 lines (51 loc) · 1.49 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;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;
namespace Xamarin.Forms.Platform.Android.UnitTests
{
[TestFixture]
public class IsEnabledTests : PlatformTestFixture
{
static IEnumerable TestCases
{
get
{
// Generate IsEnabled = true cases
foreach (var element in BasicElements)
{
element.IsEnabled = true;
yield return CreateTestCase(element)
.SetName($"{element.GetType().Name}_IsEnabled_{element.IsEnabled}");
}
// Generate IsEnabled = false cases
foreach (var element in BasicElements)
{
element.IsEnabled = false;
yield return CreateTestCase(element)
.SetName($"{element.GetType().Name}_IsEnabled_{element.IsEnabled}");
}
}
}
[Test, Category("IsEnabled"), TestCaseSource(nameof(TestCases))]
[Description("VisualElement enabled should match renderer enabled")]
public async Task EnabledConsistent(VisualElement element)
{
await Device.InvokeOnMainThreadAsync(() => {
using (var renderer = GetRenderer(element))
{
var expected = element.IsEnabled;
var nativeView = renderer.View;
ParentView(nativeView);
// Check the container control
Assert.That(renderer.View.Enabled, Is.EqualTo(expected));
// Check the actual control
var control = GetNativeControl(element);
Assert.That(control.Enabled, Is.EqualTo(expected));
UnparentView(nativeView);
}
});
}
}
}