forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadioButtonTemplateTests.cs
81 lines (70 loc) · 3.48 KB
/
RadioButtonTemplateTests.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
using System;
using System.Collections;
using NUnit.Framework;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture(Category = "RadioButton")]
public class RadioButtonTemplateTests : BaseTestFixture
{
class FrameStyleCases : IEnumerable
{
public IEnumerator GetEnumerator()
{
yield return new object[] { Frame.VerticalOptionsProperty, LayoutOptions.End };
yield return new object[] { Frame.HorizontalOptionsProperty, LayoutOptions.End };
yield return new object[] { Frame.BackgroundColorProperty, Color.Red };
yield return new object[] { Frame.BorderColorProperty, Color.Magenta };
yield return new object[] { Frame.MarginProperty, new Thickness(1, 2, 3, 4) };
yield return new object[] { Frame.OpacityProperty, 0.67 };
yield return new object[] { Frame.RotationProperty, 0.3 };
yield return new object[] { Frame.ScaleProperty, 0.8 };
yield return new object[] { Frame.ScaleXProperty, 0.9 };
yield return new object[] { Frame.ScaleYProperty, 0.95 };
yield return new object[] { Frame.TranslationXProperty, 123 };
yield return new object[] { Frame.TranslationYProperty, 321 };
}
}
[TestCaseSource(typeof(FrameStyleCases))]
[Description("Frame Style properties should not affect RadioButton")]
public void RadioButtonIgnoresFrameStyleProperties(BindableProperty property, object value)
{
var implicitFrameStyle = new Style(typeof(Frame));
implicitFrameStyle.Setters.Add(new Setter() { Property = property, Value = value });
var page = new ContentPage();
page.Resources.Add(implicitFrameStyle);
var radioButton = new RadioButton() { ControlTemplate = RadioButton.DefaultTemplate };
page.Content = radioButton;
var root = (radioButton as IControlTemplated)?.TemplateRoot as Frame;
Assert.IsNotNull(root);
Assert.That(root.GetValue(property), Is.Not.EqualTo(value), $"{property.PropertyName} should be ignored.");
}
class RadioButtonStyleCases : IEnumerable
{
public IEnumerator GetEnumerator()
{
yield return new object[] { RadioButton.VerticalOptionsProperty, LayoutOptions.End };
yield return new object[] { RadioButton.HorizontalOptionsProperty, LayoutOptions.End };
yield return new object[] { RadioButton.BackgroundColorProperty, Color.Red };
yield return new object[] { RadioButton.MarginProperty, new Thickness(1, 2, 3, 4) };
yield return new object[] { RadioButton.OpacityProperty, 0.67 };
yield return new object[] { RadioButton.RotationProperty, 0.3 };
yield return new object[] { RadioButton.ScaleProperty, 0.8};
yield return new object[] { RadioButton.ScaleXProperty, 0.9 };
yield return new object[] { RadioButton.ScaleYProperty, 0.95 };
yield return new object[] { RadioButton.TranslationXProperty, 123 };
yield return new object[] { RadioButton.TranslationYProperty, 321 };
}
}
[TestCaseSource(typeof(RadioButtonStyleCases))]
[Description("RadioButton Style properties should affect RadioButton")]
public void RadioButtonStyleSetsPropertyOnTemplateRoot(BindableProperty property, object value)
{
var radioButtonStyle = new Style(typeof(RadioButton));
radioButtonStyle.Setters.Add(new Setter() { Property = property, Value = value });
var radioButton = new RadioButton() { ControlTemplate = RadioButton.DefaultTemplate, Style = radioButtonStyle };
var root = (radioButton as IControlTemplated)?.TemplateRoot as Frame;
Assert.IsNotNull(root);
Assert.That(root.GetValue(property), Is.EqualTo(value), $"{property.PropertyName} should match.");
}
}
}