diff --git a/Microsoft.Maui-mac.slnf b/Microsoft.Maui-mac.slnf
index 748082dc09ee..4f9455660ce5 100644
--- a/Microsoft.Maui-mac.slnf
+++ b/Microsoft.Maui-mac.slnf
@@ -37,16 +37,17 @@
"src\\Core\\maps\\src\\Maps.csproj",
"src\\Core\\src\\Core.csproj",
"src\\Core\\tests\\Benchmarks\\Core.Benchmarks.csproj",
+ "src\\Core\\tests\\DeviceTests.Shared\\Core.DeviceTests.Shared.csproj",
"src\\Core\\tests\\DeviceTests\\Core.DeviceTests.csproj",
"src\\Core\\tests\\UnitTests\\Core.UnitTests.csproj",
- "src\\Graphics\\src\\Graphics\\Graphics.csproj",
- "src\\Graphics\\src\\Graphics.Skia\\Graphics.Skia.csproj",
- "src\\Graphics\\src\\Text.Markdig\\Graphics.Text.Markdig.csproj",
"src\\Essentials\\samples\\Sample.Server.WebAuthenticator\\Essentials.Sample.Server.WebAuthenticator.csproj",
"src\\Essentials\\samples\\Samples\\Essentials.Sample.csproj",
"src\\Essentials\\src\\Essentials.csproj",
"src\\Essentials\\test\\DeviceTests\\Essentials.DeviceTests.csproj",
"src\\Essentials\\test\\UnitTests\\Essentials.UnitTests.csproj",
+ "src\\Graphics\\src\\Graphics.Skia\\Graphics.Skia.csproj",
+ "src\\Graphics\\src\\Graphics\\Graphics.csproj",
+ "src\\Graphics\\src\\Text.Markdig\\Graphics.Text.Markdig.csproj",
"src\\SingleProject\\Resizetizer\\src\\Resizetizer.csproj",
"src\\SingleProject\\Resizetizer\\test\\UnitTests\\Resizetizer.UnitTests.csproj",
"src\\Templates\\src\\Microsoft.Maui.Templates.csproj",
@@ -66,4 +67,4 @@
"src\\Workload\\Microsoft.NET.Sdk.Maui\\Microsoft.NET.Sdk.Maui.csproj"
]
}
-}
+}
\ No newline at end of file
diff --git a/Microsoft.Maui.sln b/Microsoft.Maui.sln
index dec9845453a0..92b1255752f4 100644
--- a/Microsoft.Maui.sln
+++ b/Microsoft.Maui.sln
@@ -205,7 +205,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SharedSource", "SharedSourc
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks.Droid", "src\Core\tests\Benchmarks.Droid\Benchmarks.Droid.csproj", "{5B56A734-D53C-4635-A53E-F889FCFCDD66}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maps", "src\Core\maps\src\Maps.csproj", "{E8728693-3537-4007-A4DB-9F9634548755}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maps", "src\Core\maps\src\Maps.csproj", "{E8728693-3537-4007-A4DB-9F9634548755}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Graphics", "Graphics", "{E4884871-4A1B-43BC-814F-E3D6E52B1673}"
EndProject
@@ -255,6 +255,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphicsTester.Skia.Gtk", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Core.Design.UnitTests", "src\Controls\tests\Core.Design.UnitTests\Controls.Core.Design.UnitTests.csproj", "{F68932B0-81A2-4CC3-A4F7-28091EE91B23}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.DeviceTests.Shared", "src\Core\tests\DeviceTests.Shared\Core.DeviceTests.Shared.csproj", "{66CC98E3-6A1A-4C44-A23C-B575E82106EC}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -637,6 +639,10 @@ Global
{F68932B0-81A2-4CC3-A4F7-28091EE91B23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F68932B0-81A2-4CC3-A4F7-28091EE91B23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F68932B0-81A2-4CC3-A4F7-28091EE91B23}.Release|Any CPU.Build.0 = Release|Any CPU
+ {66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {66CC98E3-6A1A-4C44-A23C-B575E82106EC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -755,6 +761,7 @@ Global
{F26D31D3-CE4C-4F32-A77F-E2905C948674} = {42AB9AE1-631D-4AD4-85B7-910FF0940BDB}
{F351A992-18E4-473C-8ADD-2BA0BAA7B5A2} = {1BA0121E-0B83-4C8F-81BE-C293E7E35DCE}
{F68932B0-81A2-4CC3-A4F7-28091EE91B23} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
+ {66CC98E3-6A1A-4C44-A23C-B575E82106EC} = {C564DDD6-DE79-45CD-88EA-3F690481572A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
diff --git a/_omnisharp.sln b/_omnisharp.sln
index ac54a4835477..45d35e70d12d 100644
--- a/_omnisharp.sln
+++ b/_omnisharp.sln
@@ -12,7 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Controls", "Controls", "{45
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E1082E26-D700-4127-9329-66D673FD2D55}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maui.Controls.Sample", "src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj", "{B8DC1324-977C-46F1-B697-9064ADE6099A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.Controls.Sample", "src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj", "{B8DC1324-977C-46F1-B697-9064ADE6099A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Compatibility", "Compatibility", "{123AA89E-1638-4E0E-B828-B8F9F9F906A2}"
EndProject
@@ -90,9 +90,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtils.DeviceTests.Runne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.DeviceTests", "src\Core\tests\DeviceTests\Core.DeviceTests.csproj", "{50BCB5CD-DC2A-42AA-B921-D99B19625CE1}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Controls.Foldable", "src\Controls\Foldable\src\Controls.Foldable.csproj", "{F0A48792-ACD7-4B72-83EB-C56A70FA5A3A}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controls.Foldable", "src\Controls\Foldable\src\Controls.Foldable.csproj", "{F0A48792-ACD7-4B72-83EB-C56A70FA5A3A}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maps", "src\Core\maps\src\Maps.csproj", "{1C9F9D5A-2CF7-4ADB-A9F5-672ACC05B035}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maps", "src\Core\maps\src\Maps.csproj", "{1C9F9D5A-2CF7-4ADB-A9F5-672ACC05B035}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Graphics", "Graphics", "{E4884871-4A1B-43BC-814F-E3D6E52B1673}"
EndProject
@@ -104,6 +104,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics", "src\Graphics\sr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics.Tests", "src\Graphics\tests\Graphics.Tests\Graphics.Tests.csproj", "{56BBFDBD-254F-42B6-9984-46E19C53FB00}"
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.DeviceTests.Shared", "src\Core\tests\DeviceTests.Shared\Core.DeviceTests.Shared.csproj", "{B000E53D-AB58-42E3-8964-2B3F30ECC886}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -229,6 +231,10 @@ Global
{56BBFDBD-254F-42B6-9984-46E19C53FB00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56BBFDBD-254F-42B6-9984-46E19C53FB00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56BBFDBD-254F-42B6-9984-46E19C53FB00}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B000E53D-AB58-42E3-8964-2B3F30ECC886}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B000E53D-AB58-42E3-8964-2B3F30ECC886}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B000E53D-AB58-42E3-8964-2B3F30ECC886}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B000E53D-AB58-42E3-8964-2B3F30ECC886}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -276,6 +282,7 @@ Global
{936C47A9-A7EA-4FBD-8733-CED1D4100E69} = {E4884871-4A1B-43BC-814F-E3D6E52B1673}
{CF056C95-51C4-4366-9D06-41D2B15EFEE4} = {42AB9AE1-631D-4AD4-85B7-910FF0940BDB}
{56BBFDBD-254F-42B6-9984-46E19C53FB00} = {936C47A9-A7EA-4FBD-8733-CED1D4100E69}
+ {B000E53D-AB58-42E3-8964-2B3F30ECC886} = {C564DDD6-DE79-45CD-88EA-3F690481572A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B8ABEAD-D2B5-4370-A187-62B5ABE4EE50}
diff --git a/src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs b/src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs
index 58b6a872b951..8bb290f12270 100644
--- a/src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs
+++ b/src/BlazorWebView/tests/MauiDeviceTests/HandlerTestBase.cs
@@ -6,6 +6,7 @@
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
+using Microsoft.Maui.DeviceTests;
namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
{
diff --git a/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj b/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj
index ac8def535eba..c29f24aa0b4b 100644
--- a/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj
+++ b/src/BlazorWebView/tests/MauiDeviceTests/MauiBlazorWebView.DeviceTests.csproj
@@ -22,6 +22,7 @@
+
diff --git a/src/BlazorWebView/tests/MauiDeviceTests/MauiProgram.cs b/src/BlazorWebView/tests/MauiDeviceTests/MauiProgram.cs
index ca4a745cbed6..5a27ce1f5af7 100644
--- a/src/BlazorWebView/tests/MauiDeviceTests/MauiProgram.cs
+++ b/src/BlazorWebView/tests/MauiDeviceTests/MauiProgram.cs
@@ -1,4 +1,7 @@
-using Microsoft.Maui.Hosting;
+using System.Collections.Generic;
+using System.Reflection;
+using Microsoft.Maui.DeviceTests;
+using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.TestUtils.DeviceTests.Runners;
@@ -7,41 +10,14 @@ namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
public static class MauiProgram
{
#if ANDROID
- public static Android.Content.Context CurrentContext { get; private set; }
+ public static Android.Content.Context CurrentContext => MauiProgramDefaults.DefaultContext;
#elif WINDOWS
- public static UI.Xaml.Window DefaultWindow { get; private set; }
+ public static UI.Xaml.Window DefaultWindow => MauiProgramDefaults.DefaultWindow;
#endif
- public static MauiApp CreateMauiApp()
- {
- var x = MauiApp.CreateBuilder();
- x.ConfigureLifecycleEvents(life =>
+ public static MauiApp CreateMauiApp() =>
+ MauiProgramDefaults.CreateMauiApp(new List()
{
-#if ANDROID
- life.AddAndroid(android =>
- {
- android.OnCreate((a, b) => CurrentContext = a);
- });
-#elif WINDOWS
- life.AddWindows(windows =>
- {
- windows.OnWindowCreated((w) => DefaultWindow = w);
- });
-#endif
+ typeof(MauiProgram).Assembly
});
-
- x.ConfigureTests(new TestOptions
- {
- Assemblies =
- {
- typeof(MauiProgram).Assembly
- },
- })
- .UseHeadlessRunner(new HeadlessRunnerOptions
- {
- RequiresUIContext = true,
- })
- .UseVisualRunner();
- return x.Build();
- }
}
}
\ No newline at end of file
diff --git a/src/BlazorWebView/tests/MauiDeviceTests/Stubs/ContextStub.cs b/src/BlazorWebView/tests/MauiDeviceTests/Stubs/ContextStub.cs
deleted file mode 100644
index b304955e247f..000000000000
--- a/src/BlazorWebView/tests/MauiDeviceTests/Stubs/ContextStub.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-using System;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Maui.Animations;
-using Microsoft.Maui.MauiBlazorWebView.DeviceTests;
-using Microsoft.Maui.Platform;
-
-namespace Microsoft.Maui.DeviceTests.Stubs
-{
- class ContextStub : IMauiContext, IServiceProvider
- {
- IServiceProvider _services;
- IAnimationManager _manager;
-#if WINDOWS || ANDROID
- NavigationRootManager _windowManager;
-#endif
-
- public ContextStub(IServiceProvider services)
- {
- _services = services;
- }
-
- public IServiceProvider Services => this;
-
- public object GetService(Type serviceType)
- {
- if (serviceType == typeof(IAnimationManager))
- return _manager ??= _services.GetRequiredService();
-#if ANDROID
- if (serviceType == typeof(Android.Content.Context))
- return MauiProgram.CurrentContext;
-
- if (serviceType == typeof(NavigationRootManager))
- return _windowManager ??= new NavigationRootManager(this);
-#elif __IOS__
- if (serviceType == typeof(UIKit.UIWindow))
- return UIKit.UIApplication.SharedApplication.KeyWindow;
-#elif WINDOWS
- if (serviceType == typeof(NavigationRootManager))
- return _windowManager ??= new NavigationRootManager(MauiProgram.DefaultWindow);
-
- if (serviceType == typeof(UI.Xaml.Window))
- return MauiProgram.DefaultWindow;
-#endif
-
- return _services.GetService(serviceType);
- }
-
- public IMauiHandlersFactory Handlers =>
- Services.GetRequiredService();
-
-#if __ANDROID__
- public Android.Content.Context Context =>
- Services.GetRequiredService();
-#endif
- }
-}
\ No newline at end of file
diff --git a/src/BlazorWebView/tests/MauiDeviceTests/TestBase.cs b/src/BlazorWebView/tests/MauiDeviceTests/TestBase.cs
deleted file mode 100644
index dfba5b70da96..000000000000
--- a/src/BlazorWebView/tests/MauiDeviceTests/TestBase.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Microsoft.Maui.DeviceTests;
-using Microsoft.Maui.Dispatching;
-using Microsoft.Maui.TestUtils.DeviceTests.Runners;
-
-namespace Microsoft.Maui.MauiBlazorWebView.DeviceTests
-{
- public class TestBase
- {
- readonly Random rnd = new Random();
-
- protected Task InvokeOnMainThreadAsync(Func func) =>
- TestDispatcher.Current.DispatchAsync(func);
-
- protected Task InvokeOnMainThreadAsync(Action action) =>
- TestDispatcher.Current.DispatchAsync(action);
-
- protected Task InvokeOnMainThreadAsync(Func action) =>
- TestDispatcher.Current.DispatchAsync(action);
-
- protected Task InvokeOnMainThreadAsync(Func> func) =>
- TestDispatcher.Current.DispatchAsync(func);
-
- protected Task Wait(Func exitCondition, int timeout = 1000) =>
- AssertionExtensions.Wait(exitCondition, timeout);
- }
-}
diff --git a/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj b/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
index 22525ba645ad..9c87fdf962b5 100644
--- a/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
+++ b/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
@@ -22,6 +22,7 @@
+
diff --git a/src/Controls/tests/DeviceTests/ControlsDeviceTestExtensions.cs b/src/Controls/tests/DeviceTests/ControlsDeviceTestExtensions.cs
new file mode 100644
index 000000000000..51235240e1ca
--- /dev/null
+++ b/src/Controls/tests/DeviceTests/ControlsDeviceTestExtensions.cs
@@ -0,0 +1,55 @@
+using Microsoft.Maui.Controls;
+using Microsoft.Maui.Controls.Hosting;
+using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Handlers;
+using Microsoft.Maui.Hosting;
+using Microsoft.Maui.LifecycleEvents;
+using Xunit;
+#if ANDROID || IOS || MACCATALYST
+using ShellHandler = Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer;
+#endif
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public static class ControlsDeviceTestExtensions
+ {
+ public static MauiAppBuilder ConfigureTestBuilder(this MauiAppBuilder mauiAppBuilder)
+ {
+ return
+ mauiAppBuilder
+ .RemapForControls()
+ .ConfigureLifecycleEvents(lifecycle =>
+ {
+#if IOS || MACCATALYST
+ lifecycle
+ .AddiOS(iOS => iOS
+ .OpenUrl((app, url, options) =>
+ ApplicationModel.Platform.OpenUrl(app, url, options))
+ .ContinueUserActivity((application, userActivity, completionHandler) =>
+ ApplicationModel.Platform.ContinueUserActivity(application, userActivity, completionHandler))
+ .PerformActionForShortcutItem((application, shortcutItem, completionHandler) =>
+ ApplicationModel.Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler)));
+#elif WINDOWS
+ lifecycle
+ .AddWindows(windows =>
+ {
+ windows
+ .OnLaunched((app, e) =>
+ ApplicationModel.Platform.OnLaunched(e));
+ windows
+ .OnActivated((window, e) =>
+ ApplicationModel.Platform.OnActivated(window, e));
+ });
+#endif
+ })
+ .ConfigureMauiHandlers(handlers =>
+ {
+ handlers.AddHandler(typeof(Editor), typeof(EditorHandler));
+ handlers.AddHandler(typeof(VerticalStackLayout), typeof(LayoutHandler));
+ handlers.AddHandler(typeof(Controls.Window), typeof(WindowHandlerStub));
+ handlers.AddHandler(typeof(Controls.ContentPage), typeof(PageHandler));
+ handlers.AddHandler(typeof(MauiAppNewWindowStub), typeof(ApplicationHandler));
+ });
+ }
+ }
+}
diff --git a/src/Controls/tests/DeviceTests/HandlerTestBase.Android.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.Android.cs
similarity index 99%
rename from src/Controls/tests/DeviceTests/HandlerTestBase.Android.cs
rename to src/Controls/tests/DeviceTests/ControlsHandlerTestBase.Android.cs
index cc765eea62df..0f34c090092c 100644
--- a/src/Controls/tests/DeviceTests/HandlerTestBase.Android.cs
+++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.Android.cs
@@ -21,7 +21,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class HandlerTestBase
+ public partial class ControlsHandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler) =>
GetSemanticPlatformElement(viewHandler).ImportantForAccessibility == ImportantForAccessibility.Yes;
diff --git a/src/Controls/tests/DeviceTests/HandlerTestBase.Windows.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.Windows.cs
similarity index 99%
rename from src/Controls/tests/DeviceTests/HandlerTestBase.Windows.cs
rename to src/Controls/tests/DeviceTests/ControlsHandlerTestBase.Windows.cs
index 0d441f0ca4a7..a1f924b7a404 100644
--- a/src/Controls/tests/DeviceTests/HandlerTestBase.Windows.cs
+++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.Windows.cs
@@ -18,7 +18,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class HandlerTestBase
+ public partial class ControlsHandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler) =>
((AccessibilityView)((DependencyObject)viewHandler.PlatformView).GetValue(NativeAutomationProperties.AccessibilityViewProperty))
diff --git a/src/Controls/tests/DeviceTests/HandlerTestBase.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
similarity index 71%
rename from src/Controls/tests/DeviceTests/HandlerTestBase.cs
rename to src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
index 36b7d5e1ff78..31a6a12a29d7 100644
--- a/src/Controls/tests/DeviceTests/HandlerTestBase.cs
+++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Reflection.Metadata;
+using System.Reflection.PortableExecutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
@@ -24,12 +25,8 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class HandlerTestBase : TestBase, IDisposable
+ public partial class ControlsHandlerTestBase : HandlerTestBase, IDisposable
{
- bool _isCreated;
- protected MauiApp MauiApp { get; private set; }
- IMauiContext _mauiContext;
-
// In order to run any page level tests android needs to add itself to the decor view inside a new fragment
// that way all the lifecycle events related to being attached to the window will fire
// adding/removing that many fragments in parallel to the decor view was causing the tests to be unreliable
@@ -37,62 +34,12 @@ public partial class HandlerTestBase : TestBase, IDisposable
// There's definitely a chance that the code written to manage this process could be improved
public const string RunInNewWindowCollection = "Serialize test because it has to add itself to the main window";
- public void EnsureHandlerCreated(Action additionalCreationActions = null)
+ protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder)
{
- if (_isCreated)
- {
- return;
- }
-
- _isCreated = true;
- var appBuilder = MauiApp
- .CreateBuilder()
- .RemapForControls()
- .ConfigureLifecycleEvents(lifecycle =>
- {
-#if IOS || MACCATALYST
- lifecycle
- .AddiOS(iOS => iOS
- .OpenUrl((app, url, options) =>
- ApplicationModel.Platform.OpenUrl(app, url, options))
- .ContinueUserActivity((application, userActivity, completionHandler) =>
- ApplicationModel.Platform.ContinueUserActivity(application, userActivity, completionHandler))
- .PerformActionForShortcutItem((application, shortcutItem, completionHandler) =>
- ApplicationModel.Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler)));
-#elif WINDOWS
- lifecycle
- .AddWindows(windows =>
- {
- windows
- .OnLaunched((app, e) =>
- ApplicationModel.Platform.OnLaunched(e));
- windows
- .OnActivated((window, e) =>
- ApplicationModel.Platform.OnActivated(window, e));
- });
-#endif
- })
- .ConfigureMauiHandlers(handlers =>
- {
- handlers.AddHandler(typeof(Editor), typeof(EditorHandler));
- handlers.AddHandler(typeof(VerticalStackLayout), typeof(LayoutHandler));
- handlers.AddHandler(typeof(Controls.Window), typeof(WindowHandlerStub));
- handlers.AddHandler(typeof(Controls.ContentPage), typeof(PageHandler));
- handlers.AddHandler(typeof(MauiAppNewWindowStub), typeof(ApplicationHandler));
- });
-
- appBuilder.Services.AddSingleton(svc => TestDispatcher.Provider);
- appBuilder.Services.AddScoped(svc => TestDispatcher.Current);
- appBuilder.Services.TryAddSingleton((_) => new ApplicationStub());
-
- additionalCreationActions?.Invoke(appBuilder);
-
- MauiApp = appBuilder.Build();
-
- _mauiContext = new ContextStub(MauiApp.Services);
+ mauiAppBuilder.Services.TryAddSingleton((_) => new ApplicationStub());
+ return mauiAppBuilder.ConfigureTestBuilder();
}
-
protected void SetupShellHandlers(IMauiHandlersCollection handlers)
{
handlers.TryAddHandler(typeof(Controls.Shell), typeof(ShellHandler));
@@ -114,83 +61,18 @@ protected void SetupShellHandlers(IMauiHandlersCollection handlers)
#endif
}
- public void Dispose()
- {
- ((IDisposable)MauiApp)?.Dispose();
-
- MauiApp = null;
- _mauiContext = null;
- }
-
- protected IMauiContext MauiContext
- {
- get
- {
- EnsureHandlerCreated();
- return _mauiContext;
- }
- }
-
protected THandler CreateHandler(IElement view)
- where THandler : IElementHandler
+ where THandler : IElementHandler, new()
{
return CreateHandler(view, MauiContext);
}
- protected THandler CreateHandler(IElement element, IMauiContext mauiContext)
- where THandler : IElementHandler
- {
- var handler = Activator.CreateInstance();
-
- handler.SetMauiContext(mauiContext);
-
- handler.SetVirtualView(element);
- element.Handler = handler;
-
- if (element is IView view && handler is IViewHandler viewHandler)
- {
-#if ANDROID
- // If the Android views don't have LayoutParams set, updating some properties (e.g., Text)
- // can run into issues when deciding whether a re-layout is required. Normally this isn't
- // an issue because the LayoutParams get set when the view is added to a ViewGroup, but
- // since we're not doing that here, we need to ensure they have LayoutParams so that tests
- // which update properties don't crash.
-
- var aView = viewHandler.PlatformView as Android.Views.View;
- if (aView.LayoutParameters == null)
- {
- aView.LayoutParameters =
- new Android.Views.ViewGroup.LayoutParams(
- Android.Views.ViewGroup.LayoutParams.WrapContent,
- Android.Views.ViewGroup.LayoutParams.WrapContent);
- }
-
- var size = view.Measure(view.Width, view.Height);
- var w = size.Width;
- var h = size.Height;
-#elif IOS || MACCATALYST
- var size = view.Measure(double.PositiveInfinity, double.PositiveInfinity);
- var w = size.Width;
- var h = size.Height;
-#else
- // Windows cannot measure without the view being loaded
- // iOS needs more love when I get an IDE again
- var w = view.Width.Equals(double.NaN) ? -1 : view.Width;
- var h = view.Height.Equals(double.NaN) ? -1 : view.Height;
-#endif
-
- view.Arrange(new Rect(0, 0, w, h));
- viewHandler.PlatformArrange(view.Frame);
- }
-
- return handler;
- }
-
- protected async Task CreateHandlerAsync(IElement view) where THandler : IElementHandler =>
+ protected async Task CreateHandlerAsync(IElement view)
+ where THandler : IElementHandler, new() =>
await InvokeOnMainThreadAsync(() => CreateHandler(view));
protected Task GetValueAsync(IElement view, Func func)
- where THandler : IElementHandler
+ where THandler : IElementHandler, new()
{
return InvokeOnMainThreadAsync(() =>
{
@@ -199,16 +81,6 @@ protected Task GetValueAsync(IElement view, Func(IView view, TValue value, Action func)
- where THandler : IElementHandler
- {
- return InvokeOnMainThreadAsync(() =>
- {
- var handler = CreateHandler(view);
- func(handler, value);
- });
- }
-
protected Task CreateHandlerAndAddToWindow(IElement view, Action action)
where THandler : class, IElementHandler
{
@@ -304,7 +176,7 @@ async protected Task ValidatePropertyInitValue(
Func GetValue,
Func GetPlatformValue,
TValue expectedValue)
- where THandler : IElementHandler
+ where THandler : IElementHandler, new()
{
var values = await GetValueAsync(view, (THandler handler) =>
{
@@ -325,7 +197,7 @@ async protected Task ValidatePropertyUpdatesValue(
Func GetPlatformValue,
TValue expectedSetValue,
TValue expectedUnsetValue)
- where THandler : IElementHandler
+ where THandler : IElementHandler, new()
{
var propInfo = view.GetType().GetProperty(property);
diff --git a/src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs
similarity index 98%
rename from src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs
rename to src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs
index 2784b5ec5aab..36a35585f1df 100644
--- a/src/Controls/tests/DeviceTests/HandlerTestBase.iOS.cs
+++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.iOS.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class HandlerTestBase
+ public partial class ControlsHandlerTestBase
{
protected bool GetIsAccessibilityElement(IViewHandler viewHandler)
{
diff --git a/src/Controls/tests/DeviceTests/DispatchingTests.cs b/src/Controls/tests/DeviceTests/DispatchingTests.cs
index 81f796e92e33..b94cf1e8b73b 100644
--- a/src/Controls/tests/DeviceTests/DispatchingTests.cs
+++ b/src/Controls/tests/DeviceTests/DispatchingTests.cs
@@ -15,7 +15,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Dispatcher)]
- public class DispatchingTests : HandlerTestBase
+ public class DispatchingTests : ControlsHandlerTestBase
{
[Fact]
public async Task DispatchFromBackgroundThread()
diff --git a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs
index df9680078ae1..321740243f5f 100644
--- a/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Button/ButtonTests.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Button)]
- public partial class ButtonTests : HandlerTestBase
+ public partial class ButtonTests : ControlsHandlerTestBase
{
[Theory]
[ClassData(typeof(TextTransformCases))]
diff --git a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs
index 0fae5079b9de..f3a9785308a8 100644
--- a/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/CheckBox/CheckBoxTests.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.CheckBox)]
- public partial class CheckBoxTests : HandlerTestBase
+ public partial class CheckBoxTests : ControlsHandlerTestBase
{
[Theory("Checkbox Background Updates Correctly With BackgroundColor Property")]
[InlineData("#FF0000")]
diff --git a/src/Controls/tests/DeviceTests/Elements/Compatibility/VisualElementRendererTests.cs b/src/Controls/tests/DeviceTests/Elements/Compatibility/VisualElementRendererTests.cs
index 0cd6a6c3f4a3..1d6e91b2aa14 100644
--- a/src/Controls/tests/DeviceTests/Elements/Compatibility/VisualElementRendererTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Compatibility/VisualElementRendererTests.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Compatibility)]
- public partial class VisualElementRendererTests : HandlerTestBase
+ public partial class VisualElementRendererTests : ControlsHandlerTestBase
{
class LegacyComponent : View
{
diff --git a/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs b/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
index 0e5b5256f2b5..75101f2546ad 100644
--- a/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ContentView/ContentViewTests.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ContentView)]
- public partial class ContentViewTests : HandlerTestBase
+ public partial class ContentViewTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.Windows.cs
index b9f6aa46700b..e018a2c71cb6 100644
--- a/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.Windows.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class ContextFlyoutTests : HandlerTestBase
+ public partial class ContextFlyoutTests : ControlsHandlerTestBase
{
[Fact(DisplayName = "Context flyout creates expected WinUI elements")]
public async Task ContextFlyoutCreatesExpectedWinUIElements()
diff --git a/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.cs b/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.cs
index 899c2cf1c516..b80e9ab01aae 100644
--- a/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ContextFlyout/ContextFlyoutTests.cs
@@ -17,7 +17,7 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.MenuFlyout)]
- public partial class ContextFlyoutTests : HandlerTestBase
+ public partial class ContextFlyoutTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
index c6456d00aabf..2d0a4aacea7b 100644
--- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs
@@ -5,7 +5,7 @@
namespace Microsoft.Maui.DeviceTests
{
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
public partial class EditorTests
{
AppCompatEditText GetPlatformControl(EditorHandler handler) =>
diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs
index c5f2f0f53113..5b06873fa7ac 100644
--- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Editor)]
- public partial class EditorTests : HandlerTestBase
+ public partial class EditorTests : ControlsHandlerTestBase
{
#if !IOS && !MACCATALYST
diff --git a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs
index d7dc7809ea19..49b678f948e1 100644
--- a/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs
@@ -5,7 +5,7 @@
namespace Microsoft.Maui.DeviceTests
{
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
public partial class EditorTests
{
MauiTextView GetPlatformControl(EditorHandler handler) =>
diff --git a/src/Controls/tests/DeviceTests/Elements/ElementTests.cs b/src/Controls/tests/DeviceTests/Elements/ElementTests.cs
index 71cc25aed7e1..6a0f40c861e4 100644
--- a/src/Controls/tests/DeviceTests/Elements/ElementTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ElementTests.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Element)]
- public partial class ElementTests : HandlerTestBase
+ public partial class ElementTests : ControlsHandlerTestBase
{
[Theory("IsInAccessibleTree initializes correctly")]
[InlineData(true)]
diff --git a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs
index f48cdef27e1c..3ecaac58f253 100644
--- a/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Entry)]
- public partial class EntryTests : HandlerTestBase
+ public partial class EntryTests : ControlsHandlerTestBase
{
[Theory(DisplayName = "Text is Transformed Correctly at Initialization")]
[ClassData(typeof(TextTransformCases))]
diff --git a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Android.cs
index 9f4d55923669..0aa9aba39947 100644
--- a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Android.cs
@@ -12,7 +12,7 @@
namespace Microsoft.Maui.DeviceTests
{
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
public partial class FlyoutPageTests
{
DrawerLayout FindPlatformFlyoutView(AView aView) =>
diff --git a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Windows.cs
index df14f2001411..5f5a3019086e 100644
--- a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.Windows.cs
@@ -20,7 +20,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.FlyoutPage)]
- public partial class FlyoutPageTests : HandlerTestBase
+ public partial class FlyoutPageTests : ControlsHandlerTestBase
{
[Fact(DisplayName = "FlyoutPage Initializes with FlyoutCustomContent Set")]
public async Task FlyoutPageInitializesWithFlyoutCustomContentSet()
diff --git a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.cs b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.cs
index 43564a24703b..59b88eb648d3 100644
--- a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.cs
@@ -23,7 +23,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.FlyoutPage)]
- public partial class FlyoutPageTests : HandlerTestBase
+ public partial class FlyoutPageTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs
index 3508cb90c2cd..62b8eb0bdcab 100644
--- a/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs
+++ b/src/Controls/tests/DeviceTests/Elements/FlyoutPage/FlyoutPageTests.iOS.cs
@@ -18,7 +18,7 @@
namespace Microsoft.Maui.DeviceTests
{
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
public partial class FlyoutPageTests
{
#if MACCATALYST
diff --git a/src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs b/src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs
index 502e55c8b366..7c6a56c36606 100644
--- a/src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/FormattedStringTests.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Label)]
- public partial class FormattedStringTests : HandlerTestBase
+ public partial class FormattedStringTests : ControlsHandlerTestBase
{
[Fact]
public async Task NativeFormattedStringContainsSpan()
diff --git a/src/Controls/tests/DeviceTests/Elements/Frame/FrameTests.cs b/src/Controls/tests/DeviceTests/Elements/Frame/FrameTests.cs
index 411aa0ac9130..2e09103dbec8 100644
--- a/src/Controls/tests/DeviceTests/Elements/Frame/FrameTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Frame/FrameTests.cs
@@ -11,7 +11,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Frame)]
- public partial class FrameTests : HandlerTestBase
+ public partial class FrameTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs
index 5b52d953a35e..ff00b3beeead 100644
--- a/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Image/ImageTests.cs
@@ -12,7 +12,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Image)]
- public partial class ImageTests : HandlerTestBase
+ public partial class ImageTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs
index 158055fa05f4..7cf5c51b5de7 100644
--- a/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Label/LabelTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Label)]
- public partial class LabelTests : HandlerTestBase
+ public partial class LabelTests : ControlsHandlerTestBase
{
[Theory]
[ClassData(typeof(TextTransformCases))]
diff --git a/src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.cs b/src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.cs
index 856806b6dfe1..76e5ffda0a0e 100644
--- a/src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Layout)]
- public partial class LayoutTests : HandlerTestBase
+ public partial class LayoutTests : ControlsHandlerTestBase
{
[Theory]
[InlineData(true, true, true)]
diff --git a/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs b/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs
index b34089173565..3d2cbb29dfcc 100644
--- a/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.cs
@@ -9,9 +9,9 @@
namespace Microsoft.Maui.DeviceTests
{
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
[Category(TestCategory.ListView)]
- public partial class ListViewTests : HandlerTestBase
+ public partial class ListViewTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Windows.cs
index a3ce57d00e99..8706f3465858 100644
--- a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.Windows.cs
@@ -12,7 +12,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class ModalTests : HandlerTestBase
+ public partial class ModalTests : ControlsHandlerTestBase
{
[Theory]
[InlineData(true)]
diff --git a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs
index 322b7851a1d0..f5ce8d3e25dc 100644
--- a/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs
@@ -24,9 +24,9 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Modal)]
#if ANDROID || IOS || MACCATALYST
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
#endif
- public partial class ModalTests : HandlerTestBase
+ public partial class ModalTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Android.cs
index 639d7e1ff639..3ed5c2009727 100644
--- a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Android.cs
@@ -14,7 +14,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.NavigationPage)]
- public partial class NavigationPageTests : HandlerTestBase
+ public partial class NavigationPageTests : ControlsHandlerTestBase
{
// We only want to fire BackButtonVisible Toolbar events if the user
// is changing the default behavior of the BackButtonVisibility
diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Windows.cs
index 11b99995955e..9904e75d1d9d 100644
--- a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.Windows.cs
@@ -19,7 +19,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.NavigationPage)]
- public partial class NavigationPageTests : HandlerTestBase
+ public partial class NavigationPageTests : ControlsHandlerTestBase
{
string GetToolbarTitle(IElementHandler handler) =>
diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
index ca83b2031ff4..0edaafa57131 100644
--- a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.cs
@@ -13,8 +13,8 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.NavigationPage)]
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
- public partial class NavigationPageTests : HandlerTestBase
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
+ public partial class NavigationPageTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs
index 5f79d3aea996..8166ba33f264 100644
--- a/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs
+++ b/src/Controls/tests/DeviceTests/Elements/NavigationPage/NavigationPageTests.iOS.cs
@@ -2,7 +2,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class NavigationPageTests : HandlerTestBase
+ public partial class NavigationPageTests : ControlsHandlerTestBase
{
}
}
diff --git a/src/Controls/tests/DeviceTests/Elements/Page/PageTests.cs b/src/Controls/tests/DeviceTests/Elements/Page/PageTests.cs
index f073939a5bab..2ee0e0415a2c 100644
--- a/src/Controls/tests/DeviceTests/Elements/Page/PageTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Page/PageTests.cs
@@ -8,8 +8,8 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Page)]
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
- public partial class PageTests : HandlerTestBase
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
+ public partial class PageTests : ControlsHandlerTestBase
{
[Theory("Page Background Initializes Correctly With Background Prooperty")]
[InlineData("#FF0000")]
diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs
index f5e67c0ec84f..54cf309250f3 100644
--- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Android.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Picker)]
- public partial class PickerTests : HandlerTestBase
+ public partial class PickerTests : ControlsHandlerTestBase
{
protected Task GetPlatformControlText(MauiPicker platformView)
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs
index 5213a2bea15e..8cd903f9b5d2 100644
--- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.Windows.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class PickerTests : HandlerTestBase
+ public partial class PickerTests : ControlsHandlerTestBase
{
protected Task GetPlatformControlText(ComboBox platformView)
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs
index 649049b2d073..7b00d5ab1ef4 100644
--- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.cs
@@ -11,7 +11,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Picker)]
- public partial class PickerTests : HandlerTestBase
+ public partial class PickerTests : ControlsHandlerTestBase
{
[Fact]
public async Task ItemsUpdateWithCollectionChanges()
diff --git a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs
index 1aa82d333c70..68d99790030a 100644
--- a/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Picker/PickerTests.iOS.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class PickerTests : HandlerTestBase
+ public partial class PickerTests : ControlsHandlerTestBase
{
protected Task GetPlatformControlText(MauiPicker platformView)
{
diff --git a/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs b/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs
index 28d1efb78bc5..72c7e3f4e252 100644
--- a/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/PlatformBehaviorTests.cs
@@ -22,9 +22,9 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Behavior)]
#if ANDROID || IOS || MACCATALYST
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
#endif
- public partial class PlatformBehaviorTests : HandlerTestBase
+ public partial class PlatformBehaviorTests : ControlsHandlerTestBase
{
[Fact]
public async Task BasicLoadUnloadingWorks()
diff --git a/src/Controls/tests/DeviceTests/Elements/ScrollView/ScrollViewTests.cs b/src/Controls/tests/DeviceTests/Elements/ScrollView/ScrollViewTests.cs
index 8f43bd19d9ed..0072eddc2645 100644
--- a/src/Controls/tests/DeviceTests/Elements/ScrollView/ScrollViewTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/ScrollView/ScrollViewTests.cs
@@ -13,7 +13,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ScrollView)]
- public partial class ScrollViewTests : HandlerTestBase
+ public partial class ScrollViewTests : ControlsHandlerTestBase
{
[Theory]
[InlineData(ScrollOrientation.Vertical)]
diff --git a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs
index df848bde7163..697f8732c6ad 100644
--- a/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/SearchBar/SearchBarTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.SearchBar)]
- public partial class SearchBarTests : HandlerTestBase
+ public partial class SearchBarTests : ControlsHandlerTestBase
{
[Theory]
[ClassData(typeof(TextTransformCases))]
diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellFlyoutTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellFlyoutTests.cs
index 950d7ece0d25..13257682a799 100644
--- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellFlyoutTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellFlyoutTests.cs
@@ -15,7 +15,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class ShellTests : HandlerTestBase
+ public partial class ShellTests : ControlsHandlerTestBase
{
[Fact]
public async Task LogicalChildrenPropagateCorrectly()
diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs
index 7e17e8d52025..70f9a87f1d57 100644
--- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs
@@ -234,7 +234,7 @@ public async Task SwappingOutAndroidContextDoesntCrash()
});
var window = new Controls.Window(shell);
- var mauiContextStub1 = new ContextStub(MauiApp.Services);
+ var mauiContextStub1 = new ContextStub(MauiContext.GetApplicationServices());
var activity = mauiContextStub1.GetActivity();
mauiContextStub1.Context = new ContextThemeWrapper(activity, Resource.Style.Maui_MainTheme_NoActionBar);
@@ -246,7 +246,7 @@ await CreateHandlerAndAddToWindow(window, async (handler) =>
await shell.GoToAsync("//FlyoutItem2");
}, mauiContextStub1);
- var mauiContextStub2 = new ContextStub(MauiApp.Services);
+ var mauiContextStub2 = new ContextStub(MauiContext.GetApplicationServices());
mauiContextStub2.Context = new ContextThemeWrapper(activity, Resource.Style.Maui_MainTheme_NoActionBar);
await CreateHandlerAndAddToWindow(window, async (handler) =>
diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs
index a4f6d7fbe3b1..de3492ffef0d 100644
--- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs
@@ -15,7 +15,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Shell)]
- public partial class ShellTests : HandlerTestBase
+ public partial class ShellTests : ControlsHandlerTestBase
{
protected Task CheckFlyoutState(ShellHandler handler, bool desiredState)
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs
index 0ad62fe1c963..d8bf55da859e 100644
--- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs
@@ -19,8 +19,8 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Shell)]
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
- public partial class ShellTests : HandlerTestBase
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
+ public partial class ShellTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Windows.cs
index a92788abb3a7..a0072446dbc5 100644
--- a/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Windows.cs
@@ -19,7 +19,7 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.TabbedPage)]
- public partial class TabbedPageTests : HandlerTestBase
+ public partial class TabbedPageTests : ControlsHandlerTestBase
{
[Fact(DisplayName = "Toolbar Visible When Pushing To TabbedPage")]
public async Task ToolbarVisibleWhenPushingToTabbedPage()
diff --git a/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.cs b/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.cs
index ac705666b2e1..db17e331feb4 100644
--- a/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.cs
@@ -18,7 +18,7 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.TabbedPage)]
- public partial class TabbedPageTests : HandlerTestBase
+ public partial class TabbedPageTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/TemplatedView/TemplatedViewTests.cs b/src/Controls/tests/DeviceTests/Elements/TemplatedView/TemplatedViewTests.cs
index 3a8b4437d85f..8cef88dc07f7 100644
--- a/src/Controls/tests/DeviceTests/Elements/TemplatedView/TemplatedViewTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/TemplatedView/TemplatedViewTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.TemplatedView)]
- public partial class TemplatedViewTests : HandlerTestBase
+ public partial class TemplatedViewTests : ControlsHandlerTestBase
{
public TemplatedViewTests()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs b/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs
index 06bddcab71d3..b51c0ccb4247 100644
--- a/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Toolbar/ToolbarTests.cs
@@ -21,7 +21,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Toolbar)]
- public partial class ToolbarTests : HandlerTestBase
+ public partial class ToolbarTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs b/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs
index ee07e3159ca2..0d53b5962677 100644
--- a/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/VisualElementTests.cs
@@ -14,9 +14,9 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.VisualElement)]
#if ANDROID || IOS || MACCATALYST
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
#endif
- public partial class VisualElementTests : HandlerTestBase
+ public partial class VisualElementTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/VisualElementTreeTests.cs b/src/Controls/tests/DeviceTests/Elements/VisualElementTreeTests.cs
index 5354dbed247f..37bc1bc3ec7e 100644
--- a/src/Controls/tests/DeviceTests/Elements/VisualElementTreeTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/VisualElementTreeTests.cs
@@ -13,9 +13,9 @@ namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.VisualElementTree)]
#if ANDROID || IOS || MACCATALYST
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
#endif
- public partial class VisualElementTreeTests : HandlerTestBase
+ public partial class VisualElementTreeTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs
index e9142b146d82..96b9f96401d2 100644
--- a/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.Windows.cs
@@ -11,7 +11,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class WindowTests : HandlerTestBase
+ public partial class WindowTests : ControlsHandlerTestBase
{
[Fact]
public async Task AdornerLayerAdded()
diff --git a/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.cs b/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.cs
index 73c5a8491a85..727188c36715 100644
--- a/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.cs
+++ b/src/Controls/tests/DeviceTests/Elements/Window/WindowTests.cs
@@ -28,9 +28,9 @@ namespace Microsoft.Maui.DeviceTests
[Category(TestCategory.Window)]
#if ANDROID || IOS || MACCATALYST
- [Collection(HandlerTestBase.RunInNewWindowCollection)]
+ [Collection(ControlsHandlerTestBase.RunInNewWindowCollection)]
#endif
- public partial class WindowTests : HandlerTestBase
+ public partial class WindowTests : ControlsHandlerTestBase
{
void SetupBuilder()
{
diff --git a/src/Controls/tests/DeviceTests/GestureTests.iOS.cs b/src/Controls/tests/DeviceTests/GestureTests.iOS.cs
index c7c5190a5783..469827671b75 100644
--- a/src/Controls/tests/DeviceTests/GestureTests.iOS.cs
+++ b/src/Controls/tests/DeviceTests/GestureTests.iOS.cs
@@ -14,7 +14,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Gesture)]
- public class GestureTests : HandlerTestBase
+ public class GestureTests : ControlsHandlerTestBase
{
[Fact]
public async Task UserInteractionEnabledTrueWhenInitializedWithGestureRecognizer()
diff --git a/src/Controls/tests/DeviceTests/MauiProgram.cs b/src/Controls/tests/DeviceTests/MauiProgram.cs
new file mode 100644
index 000000000000..2a8d8289bd3c
--- /dev/null
+++ b/src/Controls/tests/DeviceTests/MauiProgram.cs
@@ -0,0 +1,25 @@
+using System.Collections.Generic;
+using System.Reflection;
+using Microsoft.Maui.Hosting;
+using Microsoft.Maui.LifecycleEvents;
+using Microsoft.Maui.TestUtils.DeviceTests.Runners;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public static class MauiProgram
+ {
+#if ANDROID
+ public static Android.Content.Context CurrentContext => MauiProgramDefaults.DefaultContext;
+#elif WINDOWS
+ public static Microsoft.UI.Xaml.Window CurrentWindow => MauiProgramDefaults.DefaultWindow;
+#endif
+
+ public static IApplication DefaultTestApp { get; private set; }
+
+ public static MauiApp CreateMauiApp() =>
+ MauiProgramDefaults.CreateMauiApp(new List()
+ {
+ typeof(MauiProgram).Assembly
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/Controls/tests/DeviceTests/Startup.cs b/src/Controls/tests/DeviceTests/Startup.cs
deleted file mode 100644
index 534b4d16b982..000000000000
--- a/src/Controls/tests/DeviceTests/Startup.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using Microsoft.Maui.Hosting;
-using Microsoft.Maui.LifecycleEvents;
-using Microsoft.Maui.TestUtils.DeviceTests.Runners;
-
-namespace Microsoft.Maui.DeviceTests
-{
- public static class MauiProgram
- {
-#if ANDROID
- public static Android.Content.Context CurrentContext { get; private set; }
-#elif WINDOWS
- public static Microsoft.UI.Xaml.Window CurrentWindow { get; private set; }
-#endif
-
- public static MauiApp CreateMauiApp() =>
- MauiApp
- .CreateBuilder()
- .ConfigureLifecycleEvents(life =>
- {
-#if ANDROID
- life.AddAndroid(android =>
- {
- android.OnCreate((a, b) => CurrentContext = a);
- });
-#elif WINDOWS
- life.AddWindows(windows =>
- {
- windows.OnWindowCreated(win => CurrentWindow = win);
- });
-#endif
- })
- .ConfigureTests(new TestOptions
- {
- Assemblies =
- {
- typeof(MauiProgram).Assembly,
- },
- })
- .UseHeadlessRunner(new HeadlessRunnerOptions
- {
- RequiresUIContext = true,
- })
- .UseVisualRunner()
- .Build();
- }
-}
\ No newline at end of file
diff --git a/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.Android.cs b/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.Android.cs
index 6569678ea318..e19b99134724 100644
--- a/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.Android.cs
+++ b/src/Controls/tests/DeviceTests/Stubs/WindowHandlerStub.Android.cs
@@ -3,7 +3,7 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
-using static Microsoft.Maui.DeviceTests.HandlerTestBase;
+using static Microsoft.Maui.DeviceTests.ControlsHandlerTestBase;
using AActivity = Android.App.Activity;
using AView = Android.Views.View;
using AViewGroup = Android.Views.ViewGroup;
diff --git a/src/Controls/tests/DeviceTests/TestBase.cs b/src/Controls/tests/DeviceTests/TestBase.cs
deleted file mode 100644
index 69301496f994..000000000000
--- a/src/Controls/tests/DeviceTests/TestBase.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Microsoft.Maui.Dispatching;
-using Microsoft.Maui.TestUtils.DeviceTests.Runners;
-
-namespace Microsoft.Maui.DeviceTests
-{
- public partial class TestBase
- {
- readonly Random rnd = new Random();
-
- protected Task InvokeOnMainThreadAsync(Func func) =>
- TestDispatcher.Current.DispatchAsync(func);
-
- protected Task InvokeOnMainThreadAsync(Action action) =>
- TestDispatcher.Current.DispatchAsync(action);
-
- protected Task InvokeOnMainThreadAsync(Func action) =>
- TestDispatcher.Current.DispatchAsync(action);
-
- protected Task InvokeOnMainThreadAsync(Func> func) =>
- TestDispatcher.Current.DispatchAsync(func);
-
- protected Task Wait(Func exitCondition, int timeout = 1000) =>
- AssertionExtensions.Wait(exitCondition, timeout);
- }
-}
diff --git a/src/Core/src/Properties/AssemblyInfo.cs b/src/Core/src/Properties/AssemblyInfo.cs
index 26da9521f669..86013117cfdb 100644
--- a/src/Core/src/Properties/AssemblyInfo.cs
+++ b/src/Core/src/Properties/AssemblyInfo.cs
@@ -33,3 +33,5 @@
[assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup")]
[assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup.UnitTests")]
[assembly: InternalsVisibleTo("Reloadify-emit")]
+[assembly: InternalsVisibleTo("Microsoft.Maui.TestUtils.DeviceTests.Runners")]
+[assembly: InternalsVisibleTo("Microsoft.Maui.DeviceTests.Shared")]
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests.Shared/Core.DeviceTests.Shared.csproj b/src/Core/tests/DeviceTests.Shared/Core.DeviceTests.Shared.csproj
new file mode 100644
index 000000000000..91217ba88c16
--- /dev/null
+++ b/src/Core/tests/DeviceTests.Shared/Core.DeviceTests.Shared.csproj
@@ -0,0 +1,33 @@
+
+
+
+ $(_MauiDotNetTfm);$(MauiPlatforms)
+ true
+ Microsoft.Maui.DeviceTests
+ Microsoft.Maui.DeviceTests.Shared
+
+ $(NoWarn),CA1416
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Core/tests/DeviceTests.Shared/GlobalNamespaces.cs b/src/Core/tests/DeviceTests.Shared/GlobalNamespaces.cs
new file mode 100644
index 000000000000..c88b852f914f
--- /dev/null
+++ b/src/Core/tests/DeviceTests.Shared/GlobalNamespaces.cs
@@ -0,0 +1,4 @@
+global using Microsoft.Maui;
+global using Microsoft.Maui.Graphics;
+global using Microsoft.Maui.Handlers;
+global using Microsoft.Maui.Platform;
diff --git a/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBase.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBase.cs
new file mode 100644
index 000000000000..adc8dab2005c
--- /dev/null
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBase.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Dispatching;
+using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Handlers;
+using Microsoft.Maui.Hosting;
+using Microsoft.Maui.Platform;
+using Microsoft.Maui.TestUtils.DeviceTests.Runners;
+using Xunit;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public class HandlerTestBase : TestBase, IDisposable
+ {
+ MauiApp _mauiApp;
+ IServiceProvider _servicesProvider;
+ IMauiContext _mauiContext;
+ bool _isCreated;
+
+ public void EnsureHandlerCreated(Action additionalCreationActions = null)
+ {
+ if (_isCreated)
+ {
+ return;
+ }
+
+ _isCreated = true;
+
+
+ var appBuilder = ConfigureBuilder(MauiApp.CreateBuilder());
+
+ additionalCreationActions?.Invoke(appBuilder);
+
+ appBuilder.Services.TryAddSingleton(svc => TestDispatcher.Provider);
+ appBuilder.Services.TryAddScoped(svc => TestDispatcher.Current);
+ appBuilder.Services.TryAddSingleton((_) => new ApplicationStub());
+
+ _mauiApp = appBuilder.Build();
+ _servicesProvider = _mauiApp.Services;
+
+ _mauiContext = new ContextStub(_servicesProvider);
+ }
+
+ protected virtual MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder)
+ {
+ return mauiAppBuilder;
+ }
+
+ protected IMauiContext MauiContext
+ {
+ get
+ {
+ EnsureHandlerCreated();
+ return _mauiContext;
+ }
+ }
+
+ protected Task SetValueAsync(IView view, TValue value, Action func)
+ where THandler : IElementHandler, new()
+ {
+ return InvokeOnMainThreadAsync(() =>
+ {
+ var handler = CreateHandler(view);
+ func(handler, value);
+ });
+ }
+
+ protected THandler CreateHandler(IElement view, IMauiContext mauiContext = null)
+ where THandler : IElementHandler, new()
+ => CreateHandler(view, mauiContext);
+
+
+ protected void InitializeViewHandler(IElement element, IElementHandler handler, IMauiContext mauiContext = null)
+ {
+ mauiContext ??= MauiContext;
+ handler.SetMauiContext(mauiContext);
+ handler.SetVirtualView(element);
+ element.Handler = handler;
+
+ if (element is IView view && handler is IViewHandler viewHandler)
+ {
+#if ANDROID
+ // If the Android views don't have LayoutParams set, updating some properties (e.g., Text)
+ // can run into issues when deciding whether a re-layout is required. Normally this isn't
+ // an issue because the LayoutParams get set when the view is added to a ViewGroup, but
+ // since we're not doing that here, we need to ensure they have LayoutParams so that tests
+ // which update properties don't crash.
+
+ var aView = viewHandler.PlatformView as Android.Views.View;
+ if (aView.LayoutParameters == null)
+ {
+ aView.LayoutParameters =
+ new Android.Views.ViewGroup.LayoutParams(
+ Android.Views.ViewGroup.LayoutParams.WrapContent,
+ Android.Views.ViewGroup.LayoutParams.WrapContent);
+ }
+
+ var size = view.Measure(view.Width, view.Height);
+ var w = size.Width;
+ var h = size.Height;
+#elif IOS || MACCATALYST
+ var size = view.Measure(double.PositiveInfinity, double.PositiveInfinity);
+ var w = size.Width;
+ var h = size.Height;
+
+ if (double.IsPositiveInfinity(w))
+ w = view.Width;
+
+ if (double.IsPositiveInfinity(h))
+ h = view.Height;
+
+#else
+ // Windows cannot measure without the view being loaded
+ // iOS needs more love when I get an IDE again
+ var w = view.Width.Equals(double.NaN) ? -1 : view.Width;
+ var h = view.Height.Equals(double.NaN) ? -1 : view.Height;
+#endif
+
+ view.Arrange(new Rect(0, 0, w, h));
+ viewHandler.PlatformArrange(view.Frame);
+ }
+ }
+
+ protected TCustomHandler CreateHandler(IElement element, IMauiContext mauiContext)
+ where THandler : IElementHandler, new()
+ where TCustomHandler : THandler, new()
+ {
+ mauiContext ??= MauiContext;
+ var handler = Activator.CreateInstance();
+ InitializeViewHandler(element, handler, mauiContext);
+ return handler;
+ }
+
+#if PLATFORM
+ protected IPlatformViewHandler CreateHandler(IElement view, Type handlerType)
+ {
+ var handler = (IPlatformViewHandler)Activator.CreateInstance(handlerType);
+ InitializeViewHandler(view, handler, MauiContext);
+ return handler;
+
+ }
+#endif
+
+ public void Dispose()
+ {
+ ((IDisposable)_mauiApp)?.Dispose();
+ _mauiApp = null;
+ _servicesProvider = null;
+ _mauiContext = null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Android.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Android.cs
similarity index 98%
rename from src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Android.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Android.cs
index 221b93784af1..1924a0d757d1 100644
--- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Android.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Android.cs
@@ -3,6 +3,8 @@
using System.Threading.Tasks;
using Android.Views;
using Android.Widget;
+using Microsoft.Maui.Handlers;
+using Microsoft.Maui.Platform;
using Xunit;
namespace Microsoft.Maui.DeviceTests
@@ -162,9 +164,8 @@ public async Task NeedsContainerWhenInputTransparent()
var handler = await CreateHandlerAsync(view);
- var viewHandler = handler as ViewHandler;
-
- Assert.True(viewHandler.NeedsContainer);
+ if (handler is ViewHandler vh)
+ Assert.True(vh.NeedsContainer);
}
protected string GetAutomationId(IViewHandler viewHandler) =>
diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs
similarity index 95%
rename from src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs
index 81df8d9db062..be4666800f6e 100644
--- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Tests.cs
@@ -1,3 +1,4 @@
+#if PLATFORM && !TIZEN
using System;
using System.IO;
using System.Threading;
@@ -10,6 +11,8 @@
namespace Microsoft.Maui.DeviceTests
{
public abstract partial class HandlerTestBase
+ where THandler : class, IViewHandler, new()
+ where TStub : IStubBase, IView, new()
{
[Fact]
public async Task DisconnectHandlerDoesntCrash()
@@ -208,6 +211,19 @@ public async Task ReturnsNonEmptyNativeBoundingBounds(int size)
{
// TODO:
}
+#if IOS || MACCATALYST
+ else if (view is ISearchBar)
+ {
+ //Search bar currently only measures to one size
+ //https://github.com/dotnet/maui/issues/11136
+ }
+#endif
+#if ANDROID
+ else if (size == 1 && view is ISwitch)
+ {
+ // https://github.com/dotnet/maui/issues/11020
+ }
+#endif
else if (view is IProgress)
{
if (!CloseEnough(size, nativeBoundingBox.Size.Width))
@@ -294,3 +310,4 @@ public void HandlersHaveAllExpectedContructors()
}
}
}
+#endif
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Windows.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Windows.cs
similarity index 99%
rename from src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Windows.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Windows.cs
index 02fc9d517e32..d39427ca81a5 100644
--- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Windows.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.Windows.cs
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
@@ -134,7 +135,7 @@ public async Task InputTransparencyInitializesCorrectly(bool inputTransparent)
var uie = await GetValueAsync(view, handler => GetHitTestVisible(handler));
// HitTestVisible should be the opposite value of InputTransparent
- if (view is LayoutStub && inputTransparent)
+ if (view is ILayout && inputTransparent)
{
// InputTransparent doesn't actually affect hit test visibility for LayoutPanel.
// The panel itself needs to always be hit test visible so it can relay input to non-transparent children.
diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.cs
similarity index 98%
rename from src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.cs
index 2a4752c14ec4..aeec9f36be31 100644
--- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.cs
@@ -1,3 +1,4 @@
+#if PLATFORM && !TIZEN
using System;
using System.Threading.Tasks;
using Microsoft.Maui.DeviceTests.Stubs;
@@ -9,8 +10,6 @@
namespace Microsoft.Maui.DeviceTests
{
public partial class HandlerTestBase : HandlerTestBase
- where THandler : class, IViewHandler, new()
- where TStub : StubBase, IView, new()
{
public static Task Wait(Func exitCondition, int timeout = 1000) =>
AssertionExtensions.Wait(exitCondition, timeout);
@@ -159,4 +158,5 @@ async protected Task ValidateUnrelatedPropertyUnaffected(
Assert.Equal(initialNativeVal, newNativeVal);
}
}
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.iOS.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.iOS.cs
similarity index 98%
rename from src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.iOS.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.iOS.cs
index 6186e4559450..fde189498d18 100644
--- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.iOS.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/HandlerTestBaseOfT.iOS.cs
@@ -4,6 +4,7 @@
using CoreGraphics;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Graphics;
+using Microsoft.Maui.Platform;
using ObjCRuntime;
using UIKit;
using Xunit;
@@ -112,7 +113,7 @@ public async Task RotationInitializeCorrectly(float rotation)
[InlineData(false)]
public async Task InputTransparencyInitializesCorrectly(bool inputTransparent)
{
- if (typeof(TStub) == typeof(LayoutStub))
+ if (typeof(TStub).IsAssignableTo(typeof(ILayout)))
{
// The platform type for Layouts (LayoutView) always has UserInteractionEnabled
// to allow for its children to be interacted with
diff --git a/src/Core/tests/DeviceTests/TestBase.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/TestBase.cs
similarity index 100%
rename from src/Core/tests/DeviceTests/TestBase.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/TestBase.cs
diff --git a/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.Android.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.Android.cs
similarity index 88%
rename from src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.Android.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.Android.cs
index 8092a7099f9f..9afde87f098f 100644
--- a/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.Android.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.Android.cs
@@ -2,13 +2,15 @@
using Android.Graphics;
using Android.Widget;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Handlers;
+using Microsoft.Maui.Hosting;
using Xunit;
using SearchView = AndroidX.AppCompat.Widget.SearchView;
namespace Microsoft.Maui.DeviceTests
{
- public partial class HandlerTestBase
+ public abstract partial class TextStyleHandlerTests
{
[Theory(DisplayName = "Font Family Initializes Correctly")]
[InlineData(null)]
@@ -16,9 +18,16 @@ public partial class HandlerTestBase
[InlineData("Dokdo")]
public async Task FontFamilyInitializesCorrectly(string family)
{
+ EnsureHandlerCreated(builder =>
+ {
+ builder
+ .ConfigureFonts(fonts =>
+ {
+ fonts.AddFont("dokdo_regular.ttf", "Dokdo");
+ });
+ });
+
var view = new TStub();
- if (view is not ITextStyle)
- return;
view.GetType().GetProperty("Font").SetValue(view, Font.OfSize(family, 10));
var handler = (await CreateHandlerAsync(view)) as ElementHandler;
diff --git a/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.cs
new file mode 100644
index 000000000000..ccc2c76a3546
--- /dev/null
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.cs
@@ -0,0 +1,118 @@
+#if PLATFORM && !TIZEN
+using System.Threading.Tasks;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Handlers;
+using Microsoft.Maui.Hosting;
+using Xunit;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public partial class TextStyleHandlerTests : HandlerTestBase
+ where THandler : class, IViewHandler, new()
+ where TStub : IStubBase, IView, ITextStyle, new()
+ {
+#if !WINDOWS
+ [Theory(DisplayName = "Font Size Initializes Correctly")]
+ [InlineData(1)]
+ [InlineData(10)]
+ [InlineData(20)]
+ [InlineData(100)]
+ public async Task FontSizeInitializesCorrectly(int fontSize)
+ {
+ var view = new TStub();
+ SetFont(view, Font.OfSize("Arial", fontSize, enableScaling: false));
+ await ValidatePropertyInitValue(view, () => view.Font.Size, (h) => GetNativeUnscaledFontSize(h, false), view.Font.Size);
+ }
+
+ [Theory(DisplayName = "Font Attributes Initialize Correctly")]
+ [InlineData(FontWeight.Regular, false, false)]
+ [InlineData(FontWeight.Bold, true, false)]
+ [InlineData(FontWeight.Regular, false, true)]
+ [InlineData(FontWeight.Bold, true, true)]
+ public async Task FontAttributesInitializeCorrectly(FontWeight weight, bool isBold, bool isItalic)
+ {
+ var view = new TStub();
+ SetFont(view, Font.OfSize("Arial", 10, weight, isItalic ? FontSlant.Italic : FontSlant.Default));
+
+ await ValidatePropertyInitValue(view, () => view.Font.Weight == FontWeight.Bold, GetNativeIsBold, isBold);
+ await ValidatePropertyInitValue(view, () => view.Font.Slant == FontSlant.Italic, GetNativeIsItalic, isItalic);
+ }
+
+ [Theory(DisplayName = "Auto Scaling Enabled Initializes Correctly")]
+ [InlineData(true)]
+ [InlineData(false)]
+ public async Task FontAutoScalingEnabledInitializesCorrectly(bool enableAutoScaling)
+ {
+ var view = new TStub();
+ SetFont(view, Font.OfSize(null, 10, enableScaling: enableAutoScaling));
+ await ValidatePropertyInitValue(view, () => view.Font.Size, (h) => GetNativeUnscaledFontSize(h, enableAutoScaling), view.Font.Size);
+ }
+
+ [Theory(DisplayName = "Font Family and Weight Initializes Correctly")]
+ [InlineData(null, FontWeight.Regular, FontSlant.Default)]
+ [InlineData(null, FontWeight.Regular, FontSlant.Italic)]
+ [InlineData(null, FontWeight.Bold, FontSlant.Default)]
+ [InlineData(null, FontWeight.Bold, FontSlant.Italic)]
+ [InlineData("Lobster Two", FontWeight.Regular, FontSlant.Default)]
+ [InlineData("Lobster Two", FontWeight.Regular, FontSlant.Italic)]
+ [InlineData("Lobster Two", FontWeight.Bold, FontSlant.Default)]
+ [InlineData("Lobster Two", FontWeight.Bold, FontSlant.Italic)]
+#if !__IOS__
+ // iOS cannot force a font to be bold like all other OS
+ [InlineData("Dokdo", FontWeight.Regular, FontSlant.Default)]
+ [InlineData("Dokdo", FontWeight.Regular, FontSlant.Italic)]
+ [InlineData("Dokdo", FontWeight.Bold, FontSlant.Default)]
+ [InlineData("Dokdo", FontWeight.Bold, FontSlant.Italic)]
+#endif
+#if __ANDROID__
+ // "monospace" is a special font name on Android
+ [InlineData("monospace", FontWeight.Regular, FontSlant.Default)]
+ [InlineData("monospace", FontWeight.Regular, FontSlant.Italic)]
+ [InlineData("monospace", FontWeight.Bold, FontSlant.Default)]
+ [InlineData("monospace", FontWeight.Bold, FontSlant.Italic)]
+#endif
+ public async Task FontFamilyAndAttributesInitializesCorrectly(string family, FontWeight weight, FontSlant slant)
+ {
+ EnsureHandlerCreated(builder =>
+ {
+ builder
+ .ConfigureFonts(fonts =>
+ {
+ fonts.AddFont("dokdo_regular.ttf", "Dokdo");
+ });
+ });
+
+ var label = new TStub();
+
+ SetFont(label, Font.OfSize(family, 30, weight, slant));
+ SetText(label);
+
+ var (isBold, isItalic) = await GetValueAsync(label, (handler) =>
+ {
+ var isBold = GetNativeIsBold(handler);
+ var isItalic = GetNativeIsItalic(handler);
+
+ return (isBold, isItalic);
+ });
+
+ Assert.Equal(weight == FontWeight.Bold, isBold);
+ Assert.Equal(slant == FontSlant.Italic, isItalic);
+ }
+#endif
+ protected virtual void SetFont(TStub stub, Font font)
+ {
+ stub.GetType().GetProperty("Font").SetValue(stub, font);
+ }
+
+ protected virtual void SetText(TStub stub)
+ {
+ string text = "Test";
+ if (stub is ITextInput ti)
+ ti.Text = text;
+ else
+ stub.GetType().GetProperty("Text").SetValue(stub, text);
+ }
+ }
+}
+#endif
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.iOS.cs b/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.iOS.cs
similarity index 98%
rename from src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.iOS.cs
rename to src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.iOS.cs
index f0921fb00153..5e64306bea0b 100644
--- a/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.iOS.cs
+++ b/src/Core/tests/DeviceTests.Shared/HandlerTests/TextStyle/TextStyleHandlerTests.iOS.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class HandlerTestBase
+ public partial class TextStyleHandlerTests
{
[Theory(DisplayName = "Font Family Initializes Correctly")]
[InlineData(null)]
diff --git a/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs b/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs
new file mode 100644
index 000000000000..6729a8f81029
--- /dev/null
+++ b/src/Core/tests/DeviceTests.Shared/MauiProgramDefaults.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Maui.Hosting;
+using Microsoft.Maui.LifecycleEvents;
+using Microsoft.Maui.TestUtils.DeviceTests.Runners;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public static class MauiProgramDefaults
+ {
+#if ANDROID
+ public static Android.Content.Context DefaultContext { get; private set; }
+#elif WINDOWS
+ public static UI.Xaml.Window DefaultWindow { get; private set; }
+#endif
+
+ public static IApplication DefaultTestApp { get; private set; }
+
+ public static MauiApp CreateMauiApp(List testAssemblies)
+ {
+ var appBuilder = MauiApp.CreateBuilder();
+ appBuilder
+ .ConfigureLifecycleEvents(life =>
+ {
+#if ANDROID
+ life.AddAndroid(android =>
+ {
+ android.OnCreate((a, b) =>
+ {
+ DefaultContext = a;
+ });
+ });
+#elif WINDOWS
+ life.AddWindows(windows =>
+ {
+ windows.OnWindowCreated((w) => DefaultWindow = w);
+ });
+#endif
+ })
+ .ConfigureTests(new TestOptions
+ {
+ Assemblies = testAssemblies,
+ })
+ .UseHeadlessRunner(new HeadlessRunnerOptions
+ {
+ RequiresUIContext = true,
+ })
+ .UseVisualRunner();
+
+ var mauiApp = appBuilder.Build();
+
+ DefaultTestApp = mauiApp.Services.GetRequiredService();
+
+ return mauiApp;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Stubs/ApplicationStub.cs b/src/Core/tests/DeviceTests.Shared/Stubs/ApplicationStub.cs
similarity index 100%
rename from src/Core/tests/DeviceTests/Stubs/ApplicationStub.cs
rename to src/Core/tests/DeviceTests.Shared/Stubs/ApplicationStub.cs
diff --git a/src/Controls/tests/DeviceTests/Stubs/ContextStub.cs b/src/Core/tests/DeviceTests.Shared/Stubs/ContextStub.cs
similarity index 87%
rename from src/Controls/tests/DeviceTests/Stubs/ContextStub.cs
rename to src/Core/tests/DeviceTests.Shared/Stubs/ContextStub.cs
index e1252e961036..b81f8c2d8bdb 100644
--- a/src/Controls/tests/DeviceTests/Stubs/ContextStub.cs
+++ b/src/Core/tests/DeviceTests.Shared/Stubs/ContextStub.cs
@@ -2,19 +2,17 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Animations;
using Microsoft.Maui.Dispatching;
-using Microsoft.Maui.Platform;
using Microsoft.Maui.TestUtils.DeviceTests.Runners;
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class ContextStub : IMauiContext, IServiceProvider
+ public class ContextStub : IMauiContext, IServiceProvider
{
IServiceProvider _services;
IAnimationManager _manager;
#if WINDOWS || ANDROID
NavigationRootManager _windowManager;
#endif
-
#if ANDROID
Android.Content.Context _androidContext;
#endif
@@ -36,21 +34,20 @@ public object GetService(Type serviceType)
return _manager ??= _services.GetRequiredService();
#if ANDROID
if (serviceType == typeof(Android.Content.Context))
- return _androidContext ?? MauiProgram.CurrentContext;
+ return MauiProgramDefaults.DefaultContext;
if (serviceType == typeof(NavigationRootManager))
return _windowManager ??= new NavigationRootManager(this);
#elif IOS || MACCATALYST
if (serviceType == typeof(UIKit.UIWindow))
- return UIKit.UIApplication.SharedApplication.KeyWindow;
+ return UIKit.UIApplication.SharedApplication.GetKeyWindow();
#elif WINDOWS
if (serviceType == typeof(NavigationRootManager))
- return _windowManager ??= new NavigationRootManager(MauiProgram.CurrentWindow);
+ return _windowManager ??= new NavigationRootManager(MauiProgramDefaults.DefaultWindow);
if (serviceType == typeof(UI.Xaml.Window))
- return MauiProgram.CurrentWindow;
+ return MauiProgramDefaults.DefaultWindow;
#endif
-
if (serviceType == typeof(IDispatcher))
return _services.GetService(serviceType) ?? TestDispatcher.Current;
@@ -66,7 +63,6 @@ public Android.Content.Context Context
get => Services.GetRequiredService();
set => _androidContext = value;
}
-
#endif
}
}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Stubs/EllipseGeometryStub.cs b/src/Core/tests/DeviceTests.Shared/Stubs/EllipseGeometryStub.cs
similarity index 100%
rename from src/Core/tests/DeviceTests/Stubs/EllipseGeometryStub.cs
rename to src/Core/tests/DeviceTests.Shared/Stubs/EllipseGeometryStub.cs
diff --git a/src/Core/tests/DeviceTests.Shared/Stubs/IStubBase.cs b/src/Core/tests/DeviceTests.Shared/Stubs/IStubBase.cs
new file mode 100644
index 000000000000..d558cf2de850
--- /dev/null
+++ b/src/Core/tests/DeviceTests.Shared/Stubs/IStubBase.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Maui.Graphics;
+
+namespace Microsoft.Maui.DeviceTests.Stubs
+{
+ public interface IStubBase : IView, IVisualTreeElement, IToolTipElement
+ {
+ new string AutomationId { get; set; }
+
+ new double Width { get; set; }
+
+ new double Height { get; set; }
+
+ new double MaximumWidth { get; set; }
+
+ new double MaximumHeight { get; set; }
+
+ new double MinimumWidth { get; set; }
+
+ new double MinimumHeight { get; set; }
+
+ new double TranslationX { get; set; }
+
+ new double TranslationY { get; set; }
+
+ new double Scale { get; set; }
+
+ new double ScaleX { get; set; }
+
+ new double ScaleY { get; set; }
+
+ new double Rotation { get; set; }
+
+ new double RotationX { get; set; }
+
+ new double RotationY { get; set; }
+
+ new double AnchorX { get; set; }
+
+ new double AnchorY { get; set; }
+
+ new Thickness Margin { get; set; }
+
+ new FlowDirection FlowDirection { get; set; }
+
+ new double Opacity { get; set; }
+
+ new Visibility Visibility { get; set; }
+
+ new Semantics Semantics { get; set; }
+
+ new Paint Background { get; set; }
+
+ new IShape Clip { get; set; }
+
+ new bool InputTransparent { get; set; }
+ new IElement Parent { get; set; }
+ }
+
+}
diff --git a/src/Core/tests/DeviceTests/Stubs/SolidPaintStub.cs b/src/Core/tests/DeviceTests.Shared/Stubs/SolidPaintStub.cs
similarity index 88%
rename from src/Core/tests/DeviceTests/Stubs/SolidPaintStub.cs
rename to src/Core/tests/DeviceTests.Shared/Stubs/SolidPaintStub.cs
index f76febc99b6e..fee6f0157bd0 100644
--- a/src/Core/tests/DeviceTests/Stubs/SolidPaintStub.cs
+++ b/src/Core/tests/DeviceTests.Shared/Stubs/SolidPaintStub.cs
@@ -2,7 +2,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- partial class SolidPaintStub : SolidPaint
+ public partial class SolidPaintStub : SolidPaint
{
public SolidPaintStub(Color color)
{
@@ -20,7 +20,7 @@ public CoreAnimation.CALayer ToCALayer(CoreGraphics.CGRect frame = default) =>
#elif __ANDROID__
public Android.Graphics.Drawables.Drawable ToDrawable()
{
- var drawable = new Microsoft.Maui.Graphics.MauiDrawable(MauiProgram.DefaultContext);
+ var drawable = new Microsoft.Maui.Graphics.MauiDrawable(MauiProgramDefaults.DefaultContext);
drawable.SetBackgroundColor(Color.ToPlatform());
return drawable;
}
diff --git a/src/Core/tests/DeviceTests/Stubs/WindowStub.cs b/src/Core/tests/DeviceTests.Shared/Stubs/WindowStub.cs
similarity index 100%
rename from src/Core/tests/DeviceTests/Stubs/WindowStub.cs
rename to src/Core/tests/DeviceTests.Shared/Stubs/WindowStub.cs
diff --git a/src/Core/tests/DeviceTests/Core.DeviceTests.csproj b/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
index 36dd2e12dbc4..bdf65fba0020 100644
--- a/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
+++ b/src/Core/tests/DeviceTests/Core.DeviceTests.csproj
@@ -28,11 +28,9 @@
-
-
-
+
@@ -61,5 +59,5 @@
-
+
diff --git a/src/Core/tests/DeviceTests/CoreDeviceTestExtensions.cs b/src/Core/tests/DeviceTests/CoreDeviceTestExtensions.cs
new file mode 100644
index 000000000000..5d79f4a34c22
--- /dev/null
+++ b/src/Core/tests/DeviceTests/CoreDeviceTestExtensions.cs
@@ -0,0 +1,33 @@
+using System;
+using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Hosting;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public static class CoreDeviceTestExtensions
+ {
+ public static MauiAppBuilder ConfigureTestBuilder(this MauiAppBuilder mauiAppBuilder)
+ {
+ return mauiAppBuilder
+ .ConfigureMauiHandlers(handlers =>
+ {
+ handlers.AddHandler(typeof(ButtonWithContainerStub), typeof(ButtonWithContainerStubHandler));
+ handlers.AddHandler(typeof(SliderStub), typeof(SliderHandler));
+ handlers.AddHandler(typeof(ButtonStub), typeof(ButtonHandler));
+ handlers.AddHandler(typeof(ElementStub), typeof(ElementHandlerStub));
+ })
+ .ConfigureImageSources(services =>
+ {
+ services.AddService();
+ })
+ .ConfigureFonts(fonts =>
+ {
+ fonts.AddFont("dokdo_regular.ttf", "Dokdo");
+ fonts.AddFont("LobsterTwo-Regular.ttf", "Lobster Two");
+ fonts.AddFont("LobsterTwo-Bold.ttf", "Lobster Two Bold");
+ fonts.AddFont("LobsterTwo-Italic.ttf", "Lobster Two Italic");
+ fonts.AddFont("LobsterTwo-BoldItalic.ttf", "Lobster Two BoldItalic");
+ });
+ }
+ }
+}
diff --git a/src/Core/tests/DeviceTests/Handlers/ActivityIndicator/ActivityIndicatorHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/ActivityIndicator/ActivityIndicatorHandlerTests.cs
index dbda9755d9a8..64b0996aa495 100644
--- a/src/Core/tests/DeviceTests/Handlers/ActivityIndicator/ActivityIndicatorHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ActivityIndicator/ActivityIndicatorHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ActivityIndicator)]
- public partial class ActivityIndicatorHandlerTests : HandlerTestBase
+ public partial class ActivityIndicatorHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "IsRunning Initializes Correctly")]
[InlineData(true)]
diff --git a/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.cs
index 795f039ad87c..542411170656 100644
--- a/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Border/BorderHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Border)]
- public partial class BorderHandlerTests : HandlerTestBase
+ public partial class BorderHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Background Initializes Correctly")]
[InlineData(0xFF0000)]
diff --git a/src/Core/tests/DeviceTests/Handlers/BoxView/BoxViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/BoxView/BoxViewHandlerTests.cs
index 0175ea51c0d1..8e822706d23e 100644
--- a/src/Core/tests/DeviceTests/Handlers/BoxView/BoxViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/BoxView/BoxViewHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.BoxView)]
- public partial class BoxViewHandlerTests : HandlerTestBase
+ public partial class BoxViewHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "BoxView Initializes Correctly")]
[InlineData(0xFF0000)]
diff --git a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.cs
index db407838d465..0de6dce0363e 100644
--- a/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Button/ButtonHandlerTests.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Button)]
- public partial class ButtonHandlerTests : HandlerTestBase
+ public partial class ButtonHandlerTests : CoreHandlerTestBase
{
const int Precision = 4;
@@ -181,5 +181,10 @@ await handler.PlatformView.AttachAndRun(async () =>
});
});
}
+
+ [Category(TestCategory.Button)]
+ public class ButtonTextStyleTests : TextStyleHandlerTests
+ {
+ }
}
}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/CheckBox/CheckBoxHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/CheckBox/CheckBoxHandlerTests.cs
index e3aff904940a..33f432ee6a3b 100644
--- a/src/Core/tests/DeviceTests/Handlers/CheckBox/CheckBoxHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/CheckBox/CheckBoxHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.CheckBox)]
- public partial class CheckBoxHandlerTests : HandlerTestBase
+ public partial class CheckBoxHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "IsChecked Initializes Correctly")]
[InlineData(true)]
diff --git a/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.cs b/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.cs
index 2adeb545adf6..7393c830f2d0 100644
--- a/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ContentView/ContentViewTests.cs
@@ -5,7 +5,7 @@
namespace Microsoft.Maui.DeviceTests.Handlers.ContentView
{
[Category(TestCategory.ContentView)]
- public partial class ContentViewTests : HandlerTestBase
+ public partial class ContentViewTests : CoreHandlerTestBase
{
[Fact]
public async Task MeasureMatchesExplicitValues()
diff --git a/src/Core/tests/DeviceTests/Handlers/CoreHandlerTestBase.cs b/src/Core/tests/DeviceTests/Handlers/CoreHandlerTestBase.cs
new file mode 100644
index 000000000000..b6ed3a0496a3
--- /dev/null
+++ b/src/Core/tests/DeviceTests/Handlers/CoreHandlerTestBase.cs
@@ -0,0 +1,12 @@
+using System;
+using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Hosting;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public abstract class CoreHandlerTestBase : HandlerTestBase, IDisposable
+ {
+ protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
+ mauiAppBuilder.ConfigureTestBuilder();
+ }
+}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/CoreHandlerTestBaseOfT.cs b/src/Core/tests/DeviceTests/Handlers/CoreHandlerTestBaseOfT.cs
new file mode 100644
index 000000000000..434f296f8071
--- /dev/null
+++ b/src/Core/tests/DeviceTests/Handlers/CoreHandlerTestBaseOfT.cs
@@ -0,0 +1,13 @@
+using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Hosting;
+
+namespace Microsoft.Maui.DeviceTests
+{
+ public abstract partial class CoreHandlerTestBase : HandlerTestBase
+ where THandler : class, IViewHandler, new()
+ where TStub : StubBase, IView, new()
+ {
+ protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder) =>
+ mauiAppBuilder.ConfigureTestBuilder();
+ }
+}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/DatePicker/DatePickerHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/DatePicker/DatePickerHandlerTests.cs
index 3d22472bb80b..f71a9de0c4d8 100644
--- a/src/Core/tests/DeviceTests/Handlers/DatePicker/DatePickerHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/DatePicker/DatePickerHandlerTests.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.DatePicker)]
- public partial class DatePickerHandlerTests : HandlerTestBase
+ public partial class DatePickerHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Date Initializes Correctly")]
public async Task DateInitializesCorrectly()
@@ -41,6 +41,16 @@ public async Task NullTextColorDoesntCrash()
await CreateHandlerAsync(datePicker);
}
+
+ [Category(TestCategory.DatePicker)]
+ public class DatePickerTextStyleTests : TextStyleHandlerTests
+ {
+
+ protected override void SetText(DatePickerStub stub)
+ {
+ stub.Date = new DateTime(2042, 1, 1);
+ }
+ }
}
}
#endif
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs
index 66170c2806d1..bbfadeb05aab 100644
--- a/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Editor/EditorHandlerTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Editor)]
- public partial class EditorHandlerTests : HandlerTestBase
+ public partial class EditorHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Text Initializes Correctly")]
public async Task TextInitializesCorrectly()
@@ -369,5 +369,10 @@ public async Task ValidateChatKeyboard(string keyboardName, bool expected)
await ValidatePropertyInitValue(editor, () => expected, GetNativeIsChatKeyboard, expected);
}
+
+ [Category(TestCategory.Editor)]
+ public class EditorTextStyleTests : TextStyleHandlerTests
+ {
+ }
}
}
diff --git a/src/Core/tests/DeviceTests/Handlers/Element/ElementTests.cs b/src/Core/tests/DeviceTests/Handlers/Element/ElementTests.cs
index 54da7d2497e4..4aa55ca9a8cf 100644
--- a/src/Core/tests/DeviceTests/Handlers/Element/ElementTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Element/ElementTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class ElementTests : HandlerTestBase
+ public partial class ElementTests : CoreHandlerTestBase
{
[Fact]
public void ElementToHandlerReturnsIElementHandler()
diff --git a/src/Core/tests/DeviceTests/Handlers/Entry/EntryHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Entry/EntryHandlerTests.cs
index 47595185af41..c762034be590 100644
--- a/src/Core/tests/DeviceTests/Handlers/Entry/EntryHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Entry/EntryHandlerTests.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Entry)]
- public partial class EntryHandlerTests : HandlerTestBase
+ public partial class EntryHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Text Initializes Correctly")]
public async Task TextInitializesCorrectly()
@@ -493,5 +493,10 @@ await ValidateUnrelatedPropertyUnaffected(
nameof(IEntry.CharacterSpacing),
() => entry.CharacterSpacing = newSize);
}
+
+ [Category(TestCategory.Entry)]
+ public class EntryTextStyleTests : TextStyleHandlerTests
+ {
+ }
}
}
diff --git a/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.cs b/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.cs
deleted file mode 100644
index c6628fef1b92..000000000000
--- a/src/Core/tests/DeviceTests/Handlers/Fonts/FontTests.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using System.Threading.Tasks;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Maui.Handlers;
-using Xunit;
-
-namespace Microsoft.Maui.DeviceTests
-{
- public partial class HandlerTestBase
- {
- [Theory(DisplayName = "Font Size Initializes Correctly")]
- [InlineData(1)]
- [InlineData(10)]
- [InlineData(20)]
- [InlineData(100)]
- public async Task FontSizeInitializesCorrectly(int fontSize)
- {
- var view = new TStub();
- if (view is not ITextStyle textStyle)
- return;
-
- view.GetType().GetProperty("Font").SetValue(view, Font.OfSize("Arial", fontSize, enableScaling: false));
- await ValidatePropertyInitValue(view, () => textStyle.Font.Size, (h) => GetNativeUnscaledFontSize(h, false), textStyle.Font.Size);
- }
-
- [Theory(DisplayName = "Font Attributes Initialize Correctly")]
- [InlineData(FontWeight.Regular, false, false)]
- [InlineData(FontWeight.Bold, true, false)]
- [InlineData(FontWeight.Regular, false, true)]
- [InlineData(FontWeight.Bold, true, true)]
- public async Task FontAttributesInitializeCorrectly(FontWeight weight, bool isBold, bool isItalic)
- {
- var view = new TStub();
- if (view is not ITextStyle textStyle)
- return;
-
- view.GetType().GetProperty("Font").SetValue(view, Font.OfSize("Arial", 10, weight, isItalic ? FontSlant.Italic : FontSlant.Default));
-
- await ValidatePropertyInitValue(view, () => textStyle.Font.Weight == FontWeight.Bold, GetNativeIsBold, isBold);
- await ValidatePropertyInitValue(view, () => textStyle.Font.Slant == FontSlant.Italic, GetNativeIsItalic, isItalic);
- }
-
- [Theory(DisplayName = "Auto Scaling Enabled Initializes Correctly")]
- [InlineData(true)]
- [InlineData(false)]
- public async Task FontAutoScalingEnabledInitializesCorrectly(bool enableAutoScaling)
- {
- var view = new TStub();
- if (view is not ITextStyle textStyle)
- return;
-
- view.GetType().GetProperty("Font").SetValue(view, Font.OfSize(null, 10, enableScaling: enableAutoScaling));
- await ValidatePropertyInitValue(view, () => textStyle.Font.Size, (h) => GetNativeUnscaledFontSize(h, enableAutoScaling), textStyle.Font.Size);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/GraphicsView/GraphicsViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/GraphicsView/GraphicsViewHandlerTests.cs
index d2666fba4e81..444c0b26362c 100644
--- a/src/Core/tests/DeviceTests/Handlers/GraphicsView/GraphicsViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/GraphicsView/GraphicsViewHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.GraphicsView)]
- public partial class GraphicsViewHandlerTests : HandlerTestBase
+ public partial class GraphicsViewHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "GraphicsView Initializes Correctly")]
[InlineData(0xFF0000)]
diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBase.cs b/src/Core/tests/DeviceTests/Handlers/HandlerTestBase.cs
deleted file mode 100644
index 60ce58c70cd2..000000000000
--- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBase.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Maui.DeviceTests.Stubs;
-using Microsoft.Maui.Dispatching;
-using Microsoft.Maui.Graphics;
-using Microsoft.Maui.Handlers;
-using Microsoft.Maui.Hosting;
-using Microsoft.Maui.TestUtils.DeviceTests.Runners;
-using Xunit;
-
-namespace Microsoft.Maui.DeviceTests
-{
- public class HandlerTestBase : TestBase, IDisposable
- {
- IApplication _app;
- MauiApp _mauiApp;
- IServiceProvider _servicesProvider;
- IMauiContext _context;
-
- public IApplication App => _app;
-
- public IMauiContext MauiContext => _context;
-
- public HandlerTestBase()
- {
- var appBuilder = MauiApp
- .CreateBuilder()
- .ConfigureMauiHandlers(handlers =>
- {
- handlers.AddHandler(typeof(ButtonWithContainerStub), typeof(ButtonWithContainerStubHandler));
- handlers.AddHandler(typeof(SliderStub), typeof(SliderHandler));
- handlers.AddHandler(typeof(ButtonStub), typeof(ButtonHandler));
- handlers.AddHandler(typeof(ElementStub), typeof(ElementHandlerStub));
- })
- .ConfigureImageSources(services =>
- {
- services.AddService();
- })
- .ConfigureFonts(fonts =>
- {
- fonts.AddFont("dokdo_regular.ttf", "Dokdo");
- fonts.AddFont("LobsterTwo-Regular.ttf", "Lobster Two");
- fonts.AddFont("LobsterTwo-Bold.ttf", "Lobster Two Bold");
- fonts.AddFont("LobsterTwo-Italic.ttf", "Lobster Two Italic");
- fonts.AddFont("LobsterTwo-BoldItalic.ttf", "Lobster Two BoldItalic");
- });
-
- appBuilder.Services.AddSingleton(svc => TestDispatcher.Provider);
- appBuilder.Services.AddScoped(svc => TestDispatcher.Current);
-
- _mauiApp = appBuilder.Build();
- _servicesProvider = _mauiApp.Services;
-
- _app = new ApplicationStub();
-
- _context = new ContextStub(_servicesProvider);
- }
-
- protected Task SetValueAsync(IView view, TValue value, Action func)
- where THandler : IElementHandler, new()
- {
- return InvokeOnMainThreadAsync(() =>
- {
- var handler = CreateHandler(view);
- func(handler, value);
- });
- }
-
- protected THandler CreateHandler(IElement view, IMauiContext mauiContext = null)
- where THandler : IElementHandler, new()
- => CreateHandler(view, mauiContext);
-
-
- protected void InitializeViewHandler(IElement element, IElementHandler handler, IMauiContext mauiContext = null)
- {
- handler.SetMauiContext(mauiContext ?? MauiContext);
-
- handler.SetVirtualView(element);
- element.Handler = handler;
-
- if (element is IView view)
- {
- view.Arrange(new Rect(0, 0, view.Width, view.Height));
-
- if (handler is IViewHandler ivh)
- ivh.PlatformArrange(view.Frame);
- }
- }
-
- protected TCustomHandler CreateHandler(IElement view, IMauiContext mauiContext)
- where THandler : IElementHandler, new()
- where TCustomHandler : THandler, new()
- {
- var handler = new TCustomHandler();
- InitializeViewHandler(view, handler, mauiContext);
- return handler;
- }
-
-
- protected IPlatformViewHandler CreateHandler(IElement view, Type handlerType)
- {
- var handler = (IPlatformViewHandler)Activator.CreateInstance(handlerType);
- InitializeViewHandler(view, handler, MauiContext);
- return handler;
-
- }
-
- public void Dispose()
- {
- ((IDisposable)_mauiApp).Dispose();
- _mauiApp = null;
- _servicesProvider = null;
- _app = null;
- _context = null;
- }
- }
-}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs
index c91081d45925..c66947b74599 100644
--- a/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Image/ImageHandlerTests.cs
@@ -21,7 +21,7 @@ public partial class ImageHandlerTests : ImageHandlerTests : HandlerTestBase
+ public abstract partial class ImageHandlerTests : CoreHandlerTestBase
where TImageHandler : class, IImageHandler, new()
where TStub : StubBase, IImageStub, new()
{
diff --git a/src/Core/tests/DeviceTests/Handlers/ImageButton/ImageButtonHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/ImageButton/ImageButtonHandlerTests.cs
index dfedd49636de..b556570fe96f 100644
--- a/src/Core/tests/DeviceTests/Handlers/ImageButton/ImageButtonHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ImageButton/ImageButtonHandlerTests.cs
@@ -11,7 +11,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ImageButton)]
- public partial class ImageButtonHandlerTests : HandlerTestBase
+ public partial class ImageButtonHandlerTests : CoreHandlerTestBase
{
const int Precision = 4;
diff --git a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs
index 3067105925c3..0f70ec18dbe6 100644
--- a/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Label/LabelHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Label)]
- public partial class LabelHandlerTests : HandlerTestBase
+ public partial class LabelHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Background Initializes Correctly")]
public async Task BackgroundInitializesCorrectly()
@@ -150,52 +150,7 @@ await ValidateUnrelatedPropertyUnaffected(
nameof(ILabel.Font),
() => label.Font = Font.SystemFontOfSize(newSize));
}
-#if !WINDOWS
- [Theory(DisplayName = "Font Family and Weight Initializes Correctly")]
- [InlineData(null, FontWeight.Regular, FontSlant.Default)]
- [InlineData(null, FontWeight.Regular, FontSlant.Italic)]
- [InlineData(null, FontWeight.Bold, FontSlant.Default)]
- [InlineData(null, FontWeight.Bold, FontSlant.Italic)]
- [InlineData("Lobster Two", FontWeight.Regular, FontSlant.Default)]
- [InlineData("Lobster Two", FontWeight.Regular, FontSlant.Italic)]
- [InlineData("Lobster Two", FontWeight.Bold, FontSlant.Default)]
- [InlineData("Lobster Two", FontWeight.Bold, FontSlant.Italic)]
-#endif
-#if !__IOS__ && !WINDOWS
- // iOS cannot force a font to be bold like all other OS
- [InlineData("Dokdo", FontWeight.Regular, FontSlant.Default)]
- [InlineData("Dokdo", FontWeight.Regular, FontSlant.Italic)]
- [InlineData("Dokdo", FontWeight.Bold, FontSlant.Default)]
- [InlineData("Dokdo", FontWeight.Bold, FontSlant.Italic)]
-#endif
-#if __ANDROID__ && !WINDOWS
- // "monospace" is a special font name on Android
- [InlineData("monospace", FontWeight.Regular, FontSlant.Default)]
- [InlineData("monospace", FontWeight.Regular, FontSlant.Italic)]
- [InlineData("monospace", FontWeight.Bold, FontSlant.Default)]
- [InlineData("monospace", FontWeight.Bold, FontSlant.Italic)]
-#endif
-#if !WINDOWS
- public async Task FontFamilyAndAttributesInitializesCorrectly(string family, FontWeight weight, FontSlant slant)
- {
- var label = new LabelStub
- {
- Text = "Test",
- Font = Font.OfSize(family, 30, weight, slant)
- };
- var (isBold, isItalic) = await GetValueAsync(label, (handler) =>
- {
- var isBold = GetNativeIsBold(handler);
- var isItalic = GetNativeIsItalic(handler);
-
- return (isBold, isItalic);
- });
-
- Assert.Equal(weight == FontWeight.Bold, isBold);
- Assert.Equal(slant == FontSlant.Italic, isItalic);
- }
-#endif
[Theory(DisplayName = "Updating Text Does Not Affect HorizontalTextAlignment")]
[InlineData("Short", "Longer Text")]
[InlineData("Long thext here", "Short")]
@@ -342,5 +297,10 @@ public async Task LineHeightInitializesCorrectly()
Assert.Equal(expectedValue, values.PlatformViewValue);
}
#endif
+
+ [Category(TestCategory.Label)]
+ public class LabelTextStyleTests : TextStyleHandlerTests
+ {
+ }
}
}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/Layout/LayoutHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Layout/LayoutHandlerTests.cs
index 1326eb04b12f..a6e4701c2b81 100644
--- a/src/Core/tests/DeviceTests/Handlers/Layout/LayoutHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Layout/LayoutHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests.Handlers.Layout
{
[Category(TestCategory.Layout)]
- public partial class LayoutHandlerTests : HandlerTestBase
+ public partial class LayoutHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Empty layout")]
public async Task EmptyLayout()
diff --git a/src/Core/tests/DeviceTests/Handlers/Navigation/NavigationViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Navigation/NavigationViewHandlerTests.cs
index 2dfb134c4136..fef04e717078 100644
--- a/src/Core/tests/DeviceTests/Handlers/Navigation/NavigationViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Navigation/NavigationViewHandlerTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.NavigationView)]
- public partial class NavigationViewHandlerTests : HandlerTestBase
+ public partial class NavigationViewHandlerTests : CoreHandlerTestBase
{
#if ANDROID || WINDOWS
[Fact(DisplayName = "Push Multiple Pages At Start")]
diff --git a/src/Core/tests/DeviceTests/Handlers/Page/PageHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Page/PageHandlerTests.cs
index 70d913348010..3664aa1d92e4 100644
--- a/src/Core/tests/DeviceTests/Handlers/Page/PageHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Page/PageHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Page)]
- public partial class PageHandlerTests : HandlerTestBase
+ public partial class PageHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Content Initializes Correctly")]
public async Task ContentInitializes()
diff --git a/src/Core/tests/DeviceTests/Handlers/Picker/PickerHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Picker/PickerHandlerTests.cs
index 39b8d374fd37..ac93ca7208a8 100644
--- a/src/Core/tests/DeviceTests/Handlers/Picker/PickerHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Picker/PickerHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Picker)]
- public partial class PickerHandlerTests : HandlerTestBase
+ public partial class PickerHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Updating Font Does Not Affect HorizontalTextAlignment")]
[InlineData(10, 20)]
@@ -82,5 +82,22 @@ await ValidateUnrelatedPropertyUnaffected(
nameof(IPicker.Title),
() => picker.Title = newText);
}
+
+ [Category(TestCategory.Picker)]
+ public class PickerTextStyleTests : TextStyleHandlerTests
+ {
+ protected override void SetText(PickerStub stub)
+ {
+ if (stub.Items.Count > 0)
+ {
+ stub.SelectedItem = stub.Items[0];
+ }
+ else
+ {
+ stub.Items = new List { "test" };
+ stub.SelectedItem = "test";
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.cs
index 52d7616a878f..3e4d43f7f305 100644
--- a/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ProgressBar/ProgressBarHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ProgressBar)]
- public partial class ProgressBarHandlerTests : HandlerTestBase
+ public partial class ProgressBarHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Progress Initializes Correctly")]
[InlineData(0.25)]
diff --git a/src/Core/tests/DeviceTests/Handlers/RadioButton/RadioButtonHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/RadioButton/RadioButtonHandlerTests.cs
index 50f47a97bc8c..f4bdaa35d4a9 100644
--- a/src/Core/tests/DeviceTests/Handlers/RadioButton/RadioButtonHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/RadioButton/RadioButtonHandlerTests.cs
@@ -6,7 +6,8 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class RadioButtonHandlerTests : HandlerTestBase
+ [Category(TestCategory.RadioButton)]
+ public partial class RadioButtonHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "IsChecked Initializes Correctly")]
[InlineData(false)]
@@ -34,6 +35,15 @@ public async Task IsCheckedInitializesCorrectly(bool isChecked)
Assert.Equal(xplatIsChecked, values.ViewValue);
Assert.Equal(expectedValue, values.PlatformViewValue);
}
+
+ [Category(TestCategory.RadioButton)]
+ public class RadioButtonTextStyleTests : TextStyleHandlerTests
+ {
+ protected override void SetText(RadioButtonStub stub)
+ {
+ stub.Content = "test";
+ }
+ }
}
}
#endif
diff --git a/src/Core/tests/DeviceTests/Handlers/RefreshView/RefreshViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/RefreshView/RefreshViewHandlerTests.cs
index 8884d23c679d..2abb9b39edef 100644
--- a/src/Core/tests/DeviceTests/Handlers/RefreshView/RefreshViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/RefreshView/RefreshViewHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category("RefreshViewHandler")]
- public partial class RefreshViewHandlerTests : HandlerTestBase
+ public partial class RefreshViewHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Is Refreshing Initializes Correctly")]
[InlineData(false)]
diff --git a/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.Android.cs b/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.Android.cs
index d5cfba81ef65..f8d534aec5c9 100644
--- a/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.Android.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.Android.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class ScrollViewHandlerTests : HandlerTestBase
+ public partial class ScrollViewHandlerTests : CoreHandlerTestBase
{
[Fact]
public async Task ContentInitializesCorrectly()
diff --git a/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.cs
index adceaf05307f..911407e055d7 100644
--- a/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ScrollView)]
- public partial class ScrollViewHandlerTests : HandlerTestBase
+ public partial class ScrollViewHandlerTests : CoreHandlerTestBase
{
}
}
diff --git a/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.iOS.cs
index f5c527a27c47..136280b5f659 100644
--- a/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.iOS.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ScrollView/ScrollViewHandlerTests.iOS.cs
@@ -11,7 +11,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class ScrollViewHandlerTests : HandlerTestBase
+ public partial class ScrollViewHandlerTests : CoreHandlerTestBase
{
[Fact]
public async Task ContentInitializesCorrectly()
diff --git a/src/Core/tests/DeviceTests/Handlers/SearchBar/SearchBarHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/SearchBar/SearchBarHandlerTests.cs
index 3059f627fac3..9d0131efe451 100644
--- a/src/Core/tests/DeviceTests/Handlers/SearchBar/SearchBarHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/SearchBar/SearchBarHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.SearchBar)]
- public partial class SearchBarHandlerTests : HandlerTestBase
+ public partial class SearchBarHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Background Initializes Correctly")]
[InlineData(0xFF0000)]
@@ -192,5 +192,10 @@ protected override void UpdateCursorStartPosition(SearchBarHandler searchBarHand
}
}
#endif
+
+ [Category(TestCategory.SearchBar)]
+ public class SearchBarTextStyleTests : TextStyleHandlerTests
+ {
+ }
}
}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/ShapeView/ShapeViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/ShapeView/ShapeViewHandlerTests.cs
index a7e7ba26c580..20368c813373 100644
--- a/src/Core/tests/DeviceTests/Handlers/ShapeView/ShapeViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/ShapeView/ShapeViewHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.ShapeView)]
- public partial class ShapeViewHandlerTests : HandlerTestBase
+ public partial class ShapeViewHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Shape Background Initializes Correctly")]
[InlineData(0xFF0000)]
diff --git a/src/Core/tests/DeviceTests/Handlers/Slider/SliderHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Slider/SliderHandlerTests.cs
index af72e025b613..233bdcef68fd 100644
--- a/src/Core/tests/DeviceTests/Handlers/Slider/SliderHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Slider/SliderHandlerTests.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Slider)]
- public partial class SliderHandlerTests : HandlerTestBase
+ public partial class SliderHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "Percent Value Initializes Correctly")]
[InlineData(0, 1, 0)]
diff --git a/src/Core/tests/DeviceTests/Handlers/Stepper/StepperHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Stepper/StepperHandlerTests.cs
index b288683f1401..00c784e3677f 100644
--- a/src/Core/tests/DeviceTests/Handlers/Stepper/StepperHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Stepper/StepperHandlerTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Stepper)]
- public partial class StepperHandlerTests : HandlerTestBase
+ public partial class StepperHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Is Value Initializes Correctly")]
public async Task ValueInitializesCorrectly()
diff --git a/src/Core/tests/DeviceTests/Handlers/Switch/SwitchHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Switch/SwitchHandlerTests.cs
index 5ecb86285062..23045d1c0e21 100644
--- a/src/Core/tests/DeviceTests/Handlers/Switch/SwitchHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Switch/SwitchHandlerTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Switch)]
- public partial class SwitchHandlerTests : HandlerTestBase
+ public partial class SwitchHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Is Toggled Initializes Correctly")]
public async Task IsToggledInitializesCorrectly()
diff --git a/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs
index aecbeb3c5d61..5aa951328d99 100644
--- a/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public abstract partial class TextInputHandlerTests : HandlerTestBase
+ public abstract partial class TextInputHandlerTests : CoreHandlerTestBase
where THandler : class, IViewHandler, new()
where TStub : StubBase, ITextInputStub, new()
{
diff --git a/src/Core/tests/DeviceTests/Handlers/TimePicker/TimePickerHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/TimePicker/TimePickerHandlerTests.cs
index 1aae7758cd22..969587c29d1d 100644
--- a/src/Core/tests/DeviceTests/Handlers/TimePicker/TimePickerHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/TimePicker/TimePickerHandlerTests.cs
@@ -9,7 +9,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.TimePicker)]
- public partial class TimePickerHandlerTests : HandlerTestBase
+ public partial class TimePickerHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Time Initializes Correctly")]
public async Task TimeInitializesCorrectly()
@@ -35,6 +35,15 @@ public async Task NullTextColorDoesntCrash()
await CreateHandlerAsync(timePicker);
}
+
+ [Category(TestCategory.TimePicker)]
+ public class TimePickerTextStyleTests : TextStyleHandlerTests
+ {
+ protected override void SetText(TimePickerStub stub)
+ {
+ stub.Time = new TimeSpan(17, 0, 0);
+ }
+ }
}
}
#endif
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Handlers/View/ViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/View/ViewHandlerTests.cs
index 9c9e5ae5c015..e83761f51ef2 100644
--- a/src/Core/tests/DeviceTests/Handlers/View/ViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/View/ViewHandlerTests.cs
@@ -10,7 +10,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.View)]
- public partial class ViewHandlerTests : HandlerTestBase
+ public partial class ViewHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "PlatformArrange triggers MapFrame")]
public async Task PlatformArrangeTriggersMapFrame()
diff --git a/src/Core/tests/DeviceTests/Handlers/WebView/WebViewHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/WebView/WebViewHandlerTests.cs
index 638d3080f994..872088347e5b 100644
--- a/src/Core/tests/DeviceTests/Handlers/WebView/WebViewHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/WebView/WebViewHandlerTests.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.WebView)]
- public partial class WebViewHandlerTests : HandlerTestBase
+ public partial class WebViewHandlerTests : CoreHandlerTestBase
{
[Theory(DisplayName = "UrlSource Initializes Correctly")]
[InlineData("https://dotnet.microsoft.com/")]
diff --git a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs
index e269d74e1695..cb552cc79a16 100644
--- a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.Windows.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class WindowHandlerTests : HandlerTestBase
+ public partial class WindowHandlerTests : CoreHandlerTestBase
{
[Fact(DisplayName = "Back Button Not Visible With No Navigation Page")]
public async Task BackButtonNotVisibleWithBasicView()
diff --git a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.cs
index 83c6c05e6579..b47987e1995e 100644
--- a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.cs
@@ -8,7 +8,7 @@
namespace Microsoft.Maui.DeviceTests
{
[Category(TestCategory.Window)]
- public partial class WindowHandlerTests : HandlerTestBase
+ public partial class WindowHandlerTests : CoreHandlerTestBase
{
//TODO: Fix this test on Android, it fails a lot of times
#if !ANDROID
diff --git a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.iOS.cs b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.iOS.cs
index 54542bc4dc5e..f1a029563881 100644
--- a/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.iOS.cs
+++ b/src/Core/tests/DeviceTests/Handlers/Window/WindowHandlerTests.iOS.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests
{
- public partial class WindowHandlerTests : HandlerTestBase
+ public partial class WindowHandlerTests : CoreHandlerTestBase
{
#if MACCATALYST
[Fact]
diff --git a/src/Core/tests/DeviceTests/MauiProgram.cs b/src/Core/tests/DeviceTests/MauiProgram.cs
index 418777b34c77..163af525e219 100644
--- a/src/Core/tests/DeviceTests/MauiProgram.cs
+++ b/src/Core/tests/DeviceTests/MauiProgram.cs
@@ -1,4 +1,5 @@
-using Microsoft.Extensions.DependencyInjection;
+using System.Collections.Generic;
+using System.Reflection;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.TestUtils.DeviceTests.Runners;
@@ -8,49 +9,17 @@ namespace Microsoft.Maui.DeviceTests
public static class MauiProgram
{
#if ANDROID
- public static Android.Content.Context DefaultContext { get; private set; }
+ public static Android.Content.Context DefaultContext => MauiProgramDefaults.DefaultContext;
#elif WINDOWS
- public static UI.Xaml.Window DefaultWindow { get; private set; }
+ public static UI.Xaml.Window DefaultWindow => MauiProgramDefaults.DefaultWindow;
#endif
public static IApplication DefaultTestApp { get; private set; }
- public static MauiApp CreateMauiApp()
- {
- var appBuilder = MauiApp.CreateBuilder();
- appBuilder
- .ConfigureLifecycleEvents(life =>
- {
-#if ANDROID
- life.AddAndroid(android =>
- {
- android.OnCreate((a, b) => DefaultContext = a);
- });
-#elif WINDOWS
- life.AddWindows(windows =>
- {
- windows.OnWindowCreated((w) => DefaultWindow = w);
- });
-#endif
- })
- .ConfigureTests(new TestOptions
- {
- Assemblies =
- {
- typeof(MauiProgram).Assembly
- },
- })
- .UseHeadlessRunner(new HeadlessRunnerOptions
- {
- RequiresUIContext = true,
- })
- .UseVisualRunner();
-
- var mauiApp = appBuilder.Build();
-
- DefaultTestApp = mauiApp.Services.GetRequiredService();
-
- return mauiApp;
- }
+ public static MauiApp CreateMauiApp() =>
+ MauiProgramDefaults.CreateMauiApp(new List()
+ {
+ typeof(MauiProgram).Assembly
+ });
}
}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Memory/MemoryTests.cs b/src/Core/tests/DeviceTests/Memory/MemoryTests.cs
index 35d45b7e61ad..6f0d06c70aa0 100644
--- a/src/Core/tests/DeviceTests/Memory/MemoryTests.cs
+++ b/src/Core/tests/DeviceTests/Memory/MemoryTests.cs
@@ -26,7 +26,7 @@ namespace Microsoft.Maui.Handlers.Memory
/// which is why we only currently run these on API 30+
///
[TestCaseOrderer("Microsoft.Maui.Handlers.Memory.MemoryTestOrdering", "Microsoft.Maui.Core.DeviceTests")]
- public class MemoryTests : HandlerTestBase, IClassFixture
+ public class MemoryTests : CoreHandlerTestBase, IClassFixture
{
MemoryTestFixture _fixture;
public MemoryTests(MemoryTestFixture fixture)
diff --git a/src/Core/tests/DeviceTests/Stubs/ContextStub.cs b/src/Core/tests/DeviceTests/Stubs/ContextStub.cs
deleted file mode 100644
index 81d1293d4a0f..000000000000
--- a/src/Core/tests/DeviceTests/Stubs/ContextStub.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using System;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Maui.Animations;
-
-namespace Microsoft.Maui.DeviceTests.Stubs
-{
- class ContextStub : IMauiContext, IServiceProvider
- {
- IServiceProvider _services;
- IAnimationManager _manager;
-#if WINDOWS || ANDROID
- NavigationRootManager _windowManager;
-#endif
-
- public ContextStub(IServiceProvider services)
- {
- _services = services;
- }
-
- public IServiceProvider Services => this;
-
- public object GetService(Type serviceType)
- {
- if (serviceType == typeof(IAnimationManager))
- return _manager ??= _services.GetRequiredService();
-#if ANDROID
- if (serviceType == typeof(Android.Content.Context))
- return MauiProgram.DefaultContext;
-
- if (serviceType == typeof(NavigationRootManager))
- return _windowManager ??= new NavigationRootManager(this);
-#elif __IOS__
- if (serviceType == typeof(UIKit.UIWindow))
- return UIKit.UIApplication.SharedApplication.GetKeyWindow();
-#elif WINDOWS
- if (serviceType == typeof(NavigationRootManager))
- return _windowManager ??= new NavigationRootManager(MauiProgram.DefaultWindow);
-
- if (serviceType == typeof(UI.Xaml.Window))
- return MauiProgram.DefaultWindow;
-#endif
-
- return _services.GetService(serviceType);
- }
-
- public IMauiHandlersFactory Handlers =>
- Services.GetRequiredService();
-
-#if __ANDROID__
- public Android.Content.Context Context =>
- Services.GetRequiredService();
-#endif
- }
-}
\ No newline at end of file
diff --git a/src/Core/tests/DeviceTests/Stubs/CountedImageHandler.Android.cs b/src/Core/tests/DeviceTests/Stubs/CountedImageHandler.Android.cs
index 75bad353b042..b7c26fa16bdc 100644
--- a/src/Core/tests/DeviceTests/Stubs/CountedImageHandler.Android.cs
+++ b/src/Core/tests/DeviceTests/Stubs/CountedImageHandler.Android.cs
@@ -34,6 +34,7 @@ public override void SetImageDrawable(Drawable drawable)
Log(drawable);
}
+ [System.Runtime.Versioning.SupportedOSPlatform("android23.0")]
public override void SetImageIcon(Icon icon)
{
base.SetImageIcon(icon);
diff --git a/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Android.cs b/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Android.cs
index 53155bab8be0..cc7af0c2af64 100644
--- a/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Android.cs
+++ b/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Android.cs
@@ -4,7 +4,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class CustomImageCacheStub
+ public class CustomImageCacheStub
{
readonly Dictionary _cache = new Dictionary();
diff --git a/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Windows.cs b/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Windows.cs
index 6eb155a0b74f..e69f7d9a41f3 100644
--- a/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Windows.cs
+++ b/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.Windows.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class CustomImageCacheStub
+ public class CustomImageCacheStub
{
readonly Dictionary _cache = new();
diff --git a/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.iOS.cs b/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.iOS.cs
index 9de498527afd..8b75bfce71f6 100644
--- a/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.iOS.cs
+++ b/src/Core/tests/DeviceTests/Stubs/CustomImageCacheStub.iOS.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class CustomImageCacheStub
+ public class CustomImageCacheStub
{
readonly Dictionary _cache = new Dictionary();
diff --git a/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.Android.cs b/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.Android.cs
index 00fcc5865d31..eb9d76027c43 100644
--- a/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.Android.cs
+++ b/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.Android.cs
@@ -6,7 +6,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class CustomImageSourceServiceStub : IImageSourceService
+ public class CustomImageSourceServiceStub : IImageSourceService
{
readonly CustomImageCacheStub _cache;
diff --git a/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.iOS.cs b/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.iOS.cs
index c41ec6ee0d7d..2c8959e70f18 100644
--- a/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.iOS.cs
+++ b/src/Core/tests/DeviceTests/Stubs/CustomImageSourceServiceStub.iOS.cs
@@ -5,7 +5,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class CustomImageSourceServiceStub : IImageSourceService
+ public class CustomImageSourceServiceStub : IImageSourceService
{
readonly CustomImageCacheStub _cache;
diff --git a/src/Core/tests/DeviceTests/Stubs/ElementHandlerStub.cs b/src/Core/tests/DeviceTests/Stubs/ElementHandlerStub.cs
index 412e1d0af79e..2afe872dcde1 100644
--- a/src/Core/tests/DeviceTests/Stubs/ElementHandlerStub.cs
+++ b/src/Core/tests/DeviceTests/Stubs/ElementHandlerStub.cs
@@ -1,5 +1,6 @@
using System;
using Microsoft.Maui.DeviceTests.Stubs;
+using Microsoft.Maui.Handlers;
namespace Microsoft.Maui.DeviceTests
{
diff --git a/src/Core/tests/DeviceTests/Stubs/LinearGradientPaintStub.cs b/src/Core/tests/DeviceTests/Stubs/LinearGradientPaintStub.cs
index 62a4284bf71a..3cd2be31a2ae 100644
--- a/src/Core/tests/DeviceTests/Stubs/LinearGradientPaintStub.cs
+++ b/src/Core/tests/DeviceTests/Stubs/LinearGradientPaintStub.cs
@@ -2,7 +2,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- partial class LinearGradientPaintStub : LinearGradientPaint
+ public class LinearGradientPaintStub : LinearGradientPaint
{
public LinearGradientPaintStub(Color startColor, Color endColor)
{
diff --git a/src/Core/tests/DeviceTests/Stubs/ShadowStub.cs b/src/Core/tests/DeviceTests/Stubs/ShadowStub.cs
index 00906eab1447..ef254876818f 100644
--- a/src/Core/tests/DeviceTests/Stubs/ShadowStub.cs
+++ b/src/Core/tests/DeviceTests/Stubs/ShadowStub.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- class ShadowStub : IShadow
+ public class ShadowStub : IShadow
{
public float Radius { get; set; }
diff --git a/src/Core/tests/DeviceTests/Stubs/StubBase.cs b/src/Core/tests/DeviceTests/Stubs/StubBase.cs
index d558cac72baf..ec1426bfc7d1 100644
--- a/src/Core/tests/DeviceTests/Stubs/StubBase.cs
+++ b/src/Core/tests/DeviceTests/Stubs/StubBase.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Maui.DeviceTests.Stubs
{
- public class StubBase : ElementStub, IView, IVisualTreeElement, IToolTipElement
+ public class StubBase : ElementStub, IStubBase
{
IElementHandler IElement.Handler
{
diff --git a/src/Core/tests/DeviceTests/TestCategory.cs b/src/Core/tests/DeviceTests/TestCategory.cs
index c8ae6bbb2c0c..686611d52697 100644
--- a/src/Core/tests/DeviceTests/TestCategory.cs
+++ b/src/Core/tests/DeviceTests/TestCategory.cs
@@ -28,6 +28,7 @@ public static class TestCategory
public const string Page = "Page";
public const string Picker = "Picker";
public const string ProgressBar = "ProgressBar";
+ public const string RadioButton = "RadioButton";
public const string ScrollView = "ScrollView";
public const string SearchBar = "SearchBar";
public const string ShapeView = "ShapeView";
diff --git a/src/TestUtils/src/DeviceTests.Runners/GlobalNamespaces.cs b/src/TestUtils/src/DeviceTests.Runners/GlobalNamespaces.cs
new file mode 100644
index 000000000000..c88b852f914f
--- /dev/null
+++ b/src/TestUtils/src/DeviceTests.Runners/GlobalNamespaces.cs
@@ -0,0 +1,4 @@
+global using Microsoft.Maui;
+global using Microsoft.Maui.Graphics;
+global using Microsoft.Maui.Handlers;
+global using Microsoft.Maui.Platform;
diff --git a/src/TestUtils/src/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj b/src/TestUtils/src/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj
index 1fea55a5e2ad..e82800fa23ef 100644
--- a/src/TestUtils/src/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj
+++ b/src/TestUtils/src/DeviceTests.Runners/TestUtils.DeviceTests.Runners.csproj
@@ -6,6 +6,7 @@
Microsoft.Maui.TestUtils.DeviceTests.Runners
Microsoft.Maui.TestUtils.DeviceTests.Runners
+ $(NoWarn),CA1416
@@ -24,6 +25,7 @@
+