Skip to content

Commit 54f9f58

Browse files
TamilarasanSF4853CopilotAnandhan Rajagopal
authored andcommitted
[Testing] Migration of Compatibility.Core platform-specific unit tests into device tests - 5 (#28193)
* Test case added * Update LabelTests.iOS.cs * test case added * code changes * reverted changes * Update src/Controls/tests/DeviceTests/Elements/TemplatedView/TemplatedViewTests.Android.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * handler code change * conflict code changes * flow direction test * Revert "flow direction test" This reverts commit 1f5c535. * Reverted changes --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Anandhan Rajagopal <97146406+anandhan-rajagopal@users.noreply.github.com>
1 parent 6d9658e commit 54f9f58

File tree

14 files changed

+902
-29
lines changed

14 files changed

+902
-29
lines changed

src/Controls/tests/DeviceTests/Elements/BoxView/BoxViewTests.Android.cs

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Threading.Tasks;
4+
using Microsoft.Maui.Controls;
35
using Microsoft.Maui.Graphics;
46
using Microsoft.Maui.Handlers;
57
using Microsoft.Maui.Platform;
8+
using Xunit;
69

710
namespace Microsoft.Maui.DeviceTests
811
{
9-
public partial class BoxViewTests
10-
{
11-
MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewViewHandler) =>
12-
boxViewViewHandler.PlatformView;
12+
public partial class BoxViewTests
13+
{
14+
MauiShapeView GetNativeBoxView(ShapeViewHandler boxViewViewHandler) =>
15+
boxViewViewHandler.PlatformView;
1316

1417
Task<float> GetPlatformOpacity(ShapeViewHandler handler)
1518
{
@@ -19,6 +22,80 @@ Task<float> GetPlatformOpacity(ShapeViewHandler handler)
1922
return nativeView.Alpha;
2023
});
2124
}
25+
26+
[Fact]
27+
[Description("The ScaleX property of a BoxView should match with native ScaleX")]
28+
public async Task ScaleXConsistent()
29+
{
30+
var boxView = new BoxView() { ScaleX = 0.45f };
31+
var expected = boxView.ScaleX;
32+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
33+
var platformBoxView = GetNativeBoxView(handler);
34+
var platformScaleX = await InvokeOnMainThreadAsync(() => platformBoxView.ScaleX);
35+
Assert.Equal(expected, platformScaleX);
36+
}
37+
38+
[Fact]
39+
[Description("The ScaleY property of a BoxView should match with native ScaleY")]
40+
public async Task ScaleYConsistent()
41+
{
42+
var boxView = new BoxView() { ScaleY = 1.23f };
43+
var expected = boxView.ScaleY;
44+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
45+
var platformBoxView = GetNativeBoxView(handler);
46+
var platformScaleY = await InvokeOnMainThreadAsync(() => platformBoxView.ScaleY);
47+
Assert.Equal(expected, platformScaleY);
48+
}
49+
50+
[Fact]
51+
[Description("The Scale property of a BoxView should match with native Scale")]
52+
public async Task ScaleConsistent()
53+
{
54+
var boxView = new BoxView() { Scale = 2.0f };
55+
var expected = boxView.Scale;
56+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
57+
var platformBoxView = GetNativeBoxView(handler);
58+
var platformScaleX = await InvokeOnMainThreadAsync(() => platformBoxView.ScaleX);
59+
var platformScaleY = await InvokeOnMainThreadAsync(() => platformBoxView.ScaleY);
60+
Assert.Equal(expected, platformScaleX);
61+
Assert.Equal(expected, platformScaleY);
62+
}
63+
64+
[Fact]
65+
[Description("The RotationX property of a BoxView should match with native RotationX")]
66+
public async Task RotationXConsistent()
67+
{
68+
var boxView = new BoxView() { RotationX = 33.0 };
69+
var expected = boxView.RotationX;
70+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
71+
var platformBoxView = GetNativeBoxView(handler);
72+
var platformRotationX = await InvokeOnMainThreadAsync(() => platformBoxView.RotationX);
73+
Assert.Equal(expected, platformRotationX);
74+
}
75+
76+
[Fact]
77+
[Description("The RotationY property of a BoxView should match with native RotationY")]
78+
public async Task RotationYConsistent()
79+
{
80+
var boxView = new BoxView() { RotationY = 87.0 };
81+
var expected = boxView.RotationY;
82+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
83+
var platformBoxView = GetNativeBoxView(handler);
84+
var platformRotationY = await InvokeOnMainThreadAsync(() => platformBoxView.RotationY);
85+
Assert.Equal(expected, platformRotationY);
86+
}
87+
88+
[Fact]
89+
[Description("The Rotation property of a BoxView should match with native Rotation")]
90+
public async Task RotationConsistent()
91+
{
92+
var boxView = new BoxView() { Rotation = 23.0 };
93+
var expected = boxView.Rotation;
94+
var handler = await CreateHandlerAsync<ShapeViewHandler>(boxView);
95+
var platformBoxView = GetNativeBoxView(handler);
96+
var platformRotation = await InvokeOnMainThreadAsync(() => platformBoxView.Rotation);
97+
Assert.Equal(expected, platformRotation);
98+
}
2299

23100
Task<bool> GetPlatformIsVisible(ShapeViewHandler boxViewViewHandler)
24101
{

src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.Android.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,79 @@ await InvokeOnMainThreadAsync(async () =>
116116
Assert.Equal(expectedValue, nativeOpacityValue);
117117
});
118118
}
119+
120+
[Fact]
121+
[Description("The ScaleX property of a Button should match with native ScaleX")]
122+
public async Task ScaleXConsistent()
123+
{
124+
var button = new Button() { ScaleX = 0.45f };
125+
var expected = button.ScaleX;
126+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
127+
var platformButton = GetPlatformButton(handler);
128+
var platformScaleX = await InvokeOnMainThreadAsync(() => platformButton.ScaleX);
129+
Assert.Equal(expected, platformScaleX);
130+
}
131+
132+
[Fact]
133+
[Description("The ScaleY property of a Button should match with native ScaleY")]
134+
public async Task ScaleYConsistent()
135+
{
136+
var button = new Button() { ScaleY = 1.23f };
137+
var expected = button.ScaleY;
138+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
139+
var platformButton = GetPlatformButton(handler);
140+
var platformScaleY = await InvokeOnMainThreadAsync(() => platformButton.ScaleY);
141+
Assert.Equal(expected, platformScaleY);
142+
}
143+
144+
[Fact]
145+
[Description("The Scale property of a Button should match with native Scale")]
146+
public async Task ScaleConsistent()
147+
{
148+
var button = new Button() { Scale = 2.0f };
149+
var expected = button.Scale;
150+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
151+
var platformButton = GetPlatformButton(handler);
152+
var platformScaleX = await InvokeOnMainThreadAsync(() => platformButton.ScaleX);
153+
var platformScaleY = await InvokeOnMainThreadAsync(() => platformButton.ScaleY);
154+
Assert.Equal(expected, platformScaleX);
155+
Assert.Equal(expected, platformScaleY);
156+
}
157+
158+
[Fact]
159+
[Description("The RotationX property of a Button should match with native RotationX")]
160+
public async Task RotationXConsistent()
161+
{
162+
var button = new Button() { RotationX = 33.0 };
163+
var expected = button.RotationX;
164+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
165+
var platformButton = GetPlatformButton(handler);
166+
var platformRotationX = await InvokeOnMainThreadAsync(() => platformButton.RotationX);
167+
Assert.Equal(expected, platformRotationX);
168+
}
169+
170+
[Fact]
171+
[Description("The RotationY property of a Button should match with native RotationY")]
172+
public async Task RotationYConsistent()
173+
{
174+
var button = new Button() { RotationY = 87.0 };
175+
var expected = button.RotationY;
176+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
177+
var platformButton = GetPlatformButton(handler);
178+
var platformRotationY = await InvokeOnMainThreadAsync(() => platformButton.RotationY);
179+
Assert.Equal(expected, platformRotationY);
180+
}
181+
182+
[Fact]
183+
[Description("The Rotation property of a Button should match with native Rotation")]
184+
public async Task RotationConsistent()
185+
{
186+
var button = new Button() { Rotation = 23.0 };
187+
var expected = button.Rotation;
188+
var handler = await CreateHandlerAsync<ButtonHandler>(button);
189+
var platformButton = GetPlatformButton(handler);
190+
var platformRotation = await InvokeOnMainThreadAsync(() => platformButton.Rotation);
191+
Assert.Equal(expected, platformRotation);
192+
}
119193
}
120194
}

src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.Android.cs

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Threading.Tasks;
34
using AndroidX.AppCompat.Widget;
45
using Microsoft.Maui.Controls;
@@ -8,11 +9,11 @@
89

910
namespace Microsoft.Maui.DeviceTests
1011
{
11-
[Collection(RunInNewWindowCollection)]
12-
public partial class CheckBoxTests
13-
{
14-
AppCompatCheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) =>
15-
checkBoxHandler.PlatformView;
12+
[Collection(RunInNewWindowCollection)]
13+
public partial class CheckBoxTests
14+
{
15+
AppCompatCheckBox GetNativeCheckBox(CheckBoxHandler checkBoxHandler) =>
16+
checkBoxHandler.PlatformView;
1617

1718
Task<float> GetPlatformOpacity(CheckBoxHandler CheckBoxHandler)
1819
{
@@ -22,6 +23,80 @@ Task<float> GetPlatformOpacity(CheckBoxHandler CheckBoxHandler)
2223
return nativeView.Alpha;
2324
});
2425
}
26+
27+
[Fact]
28+
[Description("The ScaleX property of a CheckBox should match with native ScaleX")]
29+
public async Task ScaleXConsistent()
30+
{
31+
var checkBox = new CheckBox() { ScaleX = 0.45f };
32+
var expected = checkBox.ScaleX;
33+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
34+
var PlatformCheckBox = GetNativeCheckBox(handler);
35+
var platformScaleX = await InvokeOnMainThreadAsync(() => PlatformCheckBox.ScaleX);
36+
Assert.Equal(expected, platformScaleX);
37+
}
38+
39+
[Fact]
40+
[Description("The ScaleY property of a CheckBox should match with native ScaleY")]
41+
public async Task ScaleYConsistent()
42+
{
43+
var checkBox = new CheckBox() { ScaleY = 1.23f };
44+
var expected = checkBox.ScaleY;
45+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
46+
var PlatformCheckBox = GetNativeCheckBox(handler);
47+
var platformScaleY = await InvokeOnMainThreadAsync(() => PlatformCheckBox.ScaleY);
48+
Assert.Equal(expected, platformScaleY);
49+
}
50+
51+
[Fact]
52+
[Description("The Scale property of a CheckBox should match with native Scale")]
53+
public async Task ScaleConsistent()
54+
{
55+
var checkBox = new CheckBox() { Scale = 2.0f };
56+
var expected = checkBox.Scale;
57+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
58+
var PlatformCheckBox = GetNativeCheckBox(handler);
59+
var platformScaleX = await InvokeOnMainThreadAsync(() => PlatformCheckBox.ScaleX);
60+
var platformScaleY = await InvokeOnMainThreadAsync(() => PlatformCheckBox.ScaleY);
61+
Assert.Equal(expected, platformScaleX);
62+
Assert.Equal(expected, platformScaleY);
63+
}
64+
65+
[Fact]
66+
[Description("The RotationX property of a CheckBox should match with native RotationX")]
67+
public async Task RotationXConsistent()
68+
{
69+
var checkBox = new CheckBox() { RotationX = 33.0 };
70+
var expected = checkBox.RotationX;
71+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
72+
var PlatformCheckBox = GetNativeCheckBox(handler);
73+
var platformRotationX = await InvokeOnMainThreadAsync(() => PlatformCheckBox.RotationX);
74+
Assert.Equal(expected, platformRotationX);
75+
}
76+
77+
[Fact]
78+
[Description("The RotationY property of a CheckBox should match with native RotationY")]
79+
public async Task RotationYConsistent()
80+
{
81+
var checkBox = new CheckBox() { RotationY = 87.0 };
82+
var expected = checkBox.RotationY;
83+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
84+
var PlatformCheckBox = GetNativeCheckBox(handler);
85+
var platformRotationY = await InvokeOnMainThreadAsync(() => PlatformCheckBox.RotationY);
86+
Assert.Equal(expected, platformRotationY);
87+
}
88+
89+
[Fact]
90+
[Description("The Rotation property of a CheckBox should match with native Rotation")]
91+
public async Task RotationConsistent()
92+
{
93+
var checkBox = new CheckBox() { Rotation = 23.0 };
94+
var expected = checkBox.Rotation;
95+
var handler = await CreateHandlerAsync<CheckBoxHandler>(checkBox);
96+
var PlatformCheckBox = GetNativeCheckBox(handler);
97+
var platformRotation = await InvokeOnMainThreadAsync(() => PlatformCheckBox.Rotation);
98+
Assert.Equal(expected, platformRotation);
99+
}
25100

26101
Task<bool> GetPlatformIsVisible(CheckBoxHandler checkBoxHandler)
27102
{

src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.ComponentModel;
2+
using System.Threading.Tasks;
23
using AndroidX.AppCompat.Widget;
34
using Microsoft.Maui.Controls;
45
using Microsoft.Maui.Handlers;
@@ -75,5 +76,79 @@ public async Task CursorPositionPreservedWhenTextTransformPresent()
7576

7677
Assert.Equal(2, editor.CursorPosition);
7778
}
79+
80+
[Fact]
81+
[Description("The ScaleX property of a Editor should match with native ScaleX")]
82+
public async Task ScaleXConsistent()
83+
{
84+
var editor = new Editor() { ScaleX = 0.45f };
85+
var expected = editor.ScaleX;
86+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
87+
var PlatformEditor = GetPlatformControl(handler);
88+
var platformScaleX = await InvokeOnMainThreadAsync(() => PlatformEditor.ScaleX);
89+
Assert.Equal(expected, platformScaleX);
90+
}
91+
92+
[Fact]
93+
[Description("The ScaleY property of a Editor should match with native ScaleY")]
94+
public async Task ScaleYConsistent()
95+
{
96+
var editor = new Editor() { ScaleY = 1.23f };
97+
var expected = editor.ScaleY;
98+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
99+
var PlatformEditor = GetPlatformControl(handler);
100+
var platformScaleY = await InvokeOnMainThreadAsync(() => PlatformEditor.ScaleY);
101+
Assert.Equal(expected, platformScaleY);
102+
}
103+
104+
[Fact]
105+
[Description("The Scale property of a Editor should match with native Scale")]
106+
public async Task ScaleConsistent()
107+
{
108+
var editor = new Editor() { Scale = 2.0f };
109+
var expected = editor.Scale;
110+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
111+
var PlatformEditor = GetPlatformControl(handler);
112+
var platformScaleX = await InvokeOnMainThreadAsync(() => PlatformEditor.ScaleX);
113+
var platformScaleY = await InvokeOnMainThreadAsync(() => PlatformEditor.ScaleY);
114+
Assert.Equal(expected, platformScaleX);
115+
Assert.Equal(expected, platformScaleY);
116+
}
117+
118+
[Fact]
119+
[Description("The RotationX property of a Editor should match with native RotationX")]
120+
public async Task RotationXConsistent()
121+
{
122+
var editor = new Editor() { RotationX = 33.0 };
123+
var expected = editor.RotationX;
124+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
125+
var PlatformEditor = GetPlatformControl(handler);
126+
var platformRotationX = await InvokeOnMainThreadAsync(() => PlatformEditor.RotationX);
127+
Assert.Equal(expected, platformRotationX);
128+
}
129+
130+
[Fact]
131+
[Description("The RotationY property of a Editor should match with native RotationY")]
132+
public async Task RotationYConsistent()
133+
{
134+
var editor = new Editor() { RotationY = 87.0 };
135+
var expected = editor.RotationY;
136+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
137+
var PlatformEditor = GetPlatformControl(handler);
138+
var platformRotationY = await InvokeOnMainThreadAsync(() => PlatformEditor.RotationY);
139+
Assert.Equal(expected, platformRotationY);
140+
}
141+
142+
[Fact]
143+
[Description("The Rotation property of a Editor should match with native Rotation")]
144+
public async Task RotationConsistent()
145+
{
146+
var editor = new Editor() { Rotation = 23.0 };
147+
var expected = editor.Rotation;
148+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
149+
var PlatformEditor = GetPlatformControl(handler);
150+
var platformRotation = await InvokeOnMainThreadAsync(() => PlatformEditor.Rotation);
151+
Assert.Equal(expected, platformRotation);
152+
}
78153
}
79154
}

0 commit comments

Comments
 (0)