Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[net7.0] Fix the ordering registration for tests #11492

Merged
merged 2 commits into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class ControlsHandlerTestBase : HandlerTestBase, IDisposable

protected override MauiAppBuilder ConfigureBuilder(MauiAppBuilder mauiAppBuilder)
{
mauiAppBuilder.Services.TryAddSingleton<IApplication>((_) => new ApplicationStub());
mauiAppBuilder.Services.AddSingleton<IApplication>((_) => new ApplicationStub());
return mauiAppBuilder.ConfigureTestBuilder();
}

Expand Down Expand Up @@ -67,7 +67,7 @@ protected THandler CreateHandler<THandler>(IElement view)
return CreateHandler<THandler>(view, MauiContext);
}

protected async Task<THandler> CreateHandlerAsync<THandler>(IElement view)
protected async Task<THandler> CreateHandlerAsync<THandler>(IElement view)
where THandler : IElementHandler, new() =>
await InvokeOnMainThreadAsync(() => CreateHandler<THandler>(view));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,11 @@ public async Task EmptyShellHasNoTopMargin()
var mainPage = new ContentPage();
var shell = new Shell() { CurrentItem = mainPage };

await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
{
var position = mainPage.ToPlatform().GetLocationOnScreen();
Assert.True(await AssertionExtensions.Wait(() => mainPage.ToPlatform().GetLocationOnScreen().Value.Y > 0));
var appTitleBarHeight = GetWindowRootView(handler).AppTitleBarActualHeight;
var position = mainPage.ToPlatform().GetLocationOnScreen();

Assert.True(Math.Abs(position.Value.Y - appTitleBarHeight) < 1);
});
Expand Down Expand Up @@ -555,7 +556,7 @@ public async Task SelectingTabUpdatesSelectedFlyoutItem()
shell.FlyoutBehavior = FlyoutBehavior.Locked;
});

await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
await CreateHandlerAndAddToWindow<ShellHandler>(shell, async (handler) =>
{
var flyoutItems = shell.FlyoutItems.Cast<IReadOnlyList<Element>>().ToList();
var rootView = handler.PlatformView as MauiNavigationView;
Expand All @@ -572,6 +573,9 @@ await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>

tabbedView.SelectedItem = platformTabItems[1].MenuItemsSource[1];

// Wait for the selected item to propagate to the rootview
await AssertionExtensions.Wait(() => (rootView.SelectedItem as NavigationViewItemViewModel).Data == flyoutItems[0][1]);

// Verify that the flyout item updates
Assert.Equal((rootView.SelectedItem as NavigationViewItemViewModel).Data, flyoutItems[0][1]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public async Task HeaderCorrectlyOffsetFromAppTitleBar()
await CreateHandlerAndAddToWindow<IWindowHandler>(mainPage, async (handler) =>
{
var mauiToolBar = GetPlatformToolbar(handler);
await AssertionExtensions.Wait(() => mauiToolBar.GetLocationOnScreen().Value.Y > 0);

Assert.NotNull(mauiToolBar);
Assert.True(await AssertionExtensions.Wait(() => mauiToolBar.GetLocationOnScreen().Value.Y > 0));

var position = mauiToolBar.GetLocationOnScreen();
var appTitleBarHeight = GetWindowRootView(handler).AppTitleBarActualHeight;

Expand Down Expand Up @@ -113,7 +116,10 @@ await CreateHandlerAndAddToWindow<WindowHandlerStub>(window, async (handler) =>
if (nextRootPage is NavigationPage || nextRootPage is Shell)
{
var mauiToolBar = GetPlatformToolbar(handler);
await AssertionExtensions.Wait(() => mauiToolBar.GetLocationOnScreen().Value.Y > 0);

Assert.NotNull(mauiToolBar);
Assert.True(await AssertionExtensions.Wait(() => mauiToolBar.GetLocationOnScreen().Value.Y > 0));

var position = mauiToolBar.GetLocationOnScreen();
var appTitleBarHeight = GetWindowRootView(handler).AppTitleBarActualHeight;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ public void EnsureHandlerCreated(Action<MauiAppBuilder> additionalCreationAction
_isCreated = true;


var appBuilder = ConfigureBuilder(MauiApp.CreateBuilder());
var appBuilder = MauiApp.CreateBuilder();

additionalCreationActions?.Invoke(appBuilder);
appBuilder.Services.AddSingleton<IDispatcherProvider>(svc => TestDispatcher.Provider);
appBuilder.Services.AddScoped<IDispatcher>(svc => TestDispatcher.Current);
appBuilder.Services.AddSingleton<IApplication>((_) => new CoreApplicationStub());

appBuilder.Services.TryAddSingleton<IDispatcherProvider>(svc => TestDispatcher.Provider);
appBuilder.Services.TryAddScoped<IDispatcher>(svc => TestDispatcher.Current);
appBuilder.Services.TryAddSingleton<IApplication>((_) => new ApplicationStub());
appBuilder = ConfigureBuilder(appBuilder);
additionalCreationActions?.Invoke(appBuilder);

_mauiApp = appBuilder.Build();
_servicesProvider = _mauiApp.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Microsoft.Maui.DeviceTests.Stubs
{
class ApplicationStub : IApplication
class CoreApplicationStub : IApplication
{
readonly List<IWindow> _windows = new List<IWindow>();

Expand Down