Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
MartyIX committed Mar 13, 2024
1 parent 2b134bb commit ad7192d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/Controls/tests/Core.UnitTests/DeviceUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.UnitTests;
using Xunit;

Expand Down Expand Up @@ -147,7 +146,7 @@ async Task boom()
await Assert.ThrowsAsync<ApplicationException>(MethodThatThrows);
});

private void MockPlatformServices(Action onInvokeOnMainThread, Action<Action> invokeOnMainThread = null)
private static void MockPlatformServices(Action onInvokeOnMainThread, Action<Action> invokeOnMainThread = null)
{
DispatcherProviderStubOptions.InvokeOnMainThread =
action =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public async Task TextPackageCorrectlySetsOnCompatibleTarget(Type fieldType, str

[Theory]
[InlineData(typeof(DatePicker), "12/12/2020 12:00:00 AM")]
public void DateTextPackageCorrectlySetsOnCompatibleTarget(Type fieldType, string result)
public async Task DateTextPackageCorrectlySetsOnCompatibleTarget(Type fieldType, string result)
{
var date = DateTime.Parse(result);
result = date.ToString();
TextPackageCorrectlySetsOnCompatibleTarget(fieldType, result);
await TextPackageCorrectlySetsOnCompatibleTarget(fieldType, result);
}

[Fact]
Expand Down
8 changes: 5 additions & 3 deletions src/Controls/tests/Core.UnitTests/NavigationUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Handlers;
using Xunit;

namespace Microsoft.Maui.Controls.Core.UnitTests
Expand Down Expand Up @@ -556,7 +555,7 @@ public async Task DoesNotSendBackEventToNonCurrentPage(bool useMaui)
{
var current = new BackButtonPage();
var navPage = new TestNavigationPage(useMaui, current);
navPage.PushAsync(new ContentPage());
await navPage.PushAsync(new ContentPage());

var emitted = false;
current.BackPressed += (sender, args) => emitted = true;
Expand Down Expand Up @@ -912,8 +911,11 @@ internal class BackButtonPage : ContentPage

protected override bool OnBackButtonPressed()
{
if (BackPressed != null)
if (BackPressed is not null)
{
BackPressed(this, EventArgs.Empty);
}

return Handle;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Controls/tests/Core.UnitTests/ScrollViewUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Graphics;
using NSubstitute;
using Xunit;

Expand Down
4 changes: 3 additions & 1 deletion src/Controls/tests/Core.UnitTests/ShellLifeCycleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public void EnsureOnAppearingFiresAfterParentIsSet(bool templated)
page.Appearing += (_, __) =>
{
if (page.Parent == null || !parentSet)
{
throw new Exception("Appearing firing before parent set is called");
}

pageAppearing = true;
};
Expand Down Expand Up @@ -185,7 +187,7 @@ public async Task EnsureOnAppearingFiresForPushedPage()
{
Shell shell = new TestShell();
shell.Items.Add(CreateShellItem());
shell.Navigation.PushAsync(new LifeCyclePage());
await shell.Navigation.PushAsync(new LifeCyclePage());
var page = (LifeCyclePage)shell.GetVisiblePage();
Assert.True(page.Appearing);
Assert.True(page.ParentSet);
Expand Down
6 changes: 3 additions & 3 deletions src/Controls/tests/Core.UnitTests/ShellTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ public async Task UriNavigationTests()
shell.Items.Add(item1);
shell.Items.Add(item2);

shell.GoToAsync("//rootlevelcontent2");
await shell.GoToAsync("//rootlevelcontent2");
Assert.Equal(shell.CurrentItem, item2);

shell.GoToAsync("//rootlevelcontent1");
await shell.GoToAsync("//rootlevelcontent1");
Assert.Equal(shell.CurrentItem, item1);
}

Expand Down Expand Up @@ -1292,7 +1292,7 @@ public async Task GetCurrentPageBetweenSections()
page = shell.CurrentPage;
};

shell.GoToAsync(new ShellNavigationState("//two/tabfour/"));
await shell.GoToAsync(new ShellNavigationState("//two/tabfour/"));
Assert.NotNull(page);
Assert.IsType<ShellTestPage>(page);
Assert.Equal((tabfour as IShellSectionController).PresentedPage, page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public static async Task Run(Func<Task> asyncMethod)
// Invoke the function and alert the context when it's complete
var task = asyncMethod() ?? throw new InvalidOperationException("No task provided.");

task.ContinueWith(async (t, o) => await context.Complete(), TaskScheduler.Default);
_ = task.ContinueWith(async (t, o) => await context.Complete(), TaskScheduler.Default);

// Start working through the queue
// Start working through the queue
context.RunOnCurrentThread();

await task;
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/tests/Core.UnitTests/ToolbarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task RemoveRootPageHidesBackButton()
IToolbarElement toolbarElement = window;
var startingPage = new TestNavigationPage(true, new ContentPage());
window.Page = startingPage;
startingPage.Navigation.PushAsync(new ContentPage());
await startingPage.Navigation.PushAsync(new ContentPage());
startingPage.Navigation.RemovePage(startingPage.RootPage);
await Task.Delay(50);
Assert.False(toolbarElement.Toolbar.BackButtonVisible);
Expand Down
18 changes: 13 additions & 5 deletions src/Controls/tests/Core.UnitTests/ViewUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Devices;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using NSubstitute;
using Xunit;

namespace Microsoft.Maui.Controls.Core.UnitTests
Expand All @@ -23,7 +20,10 @@ public ViewUnitTests()
MockPlatformSizeService.Current.GetPlatformSizeFunc = (ve, widthConstraint, heightConstraint) =>
{
if (widthConstraint < 30)
{
return new SizeRequest(new Size(40, 50));
}

return new SizeRequest(new Size(20, 100));
};
}
Expand Down Expand Up @@ -538,7 +538,7 @@ public async Task StartTimerSimple()
{
var task = new TaskCompletionSource<bool>();

Task.Factory.StartNew(() => Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
_ = Task.Factory.StartNew(() => Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
{
task.SetResult(false);
return false;
Expand All @@ -554,11 +554,14 @@ public async Task StartTimerMultiple()
var task = new TaskCompletionSource<int>();

int steps = 0;
Task.Factory.StartNew(() => Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
_ = Task.Factory.StartNew(() => Device.StartTimer(TimeSpan.FromMilliseconds(200), () =>
{
steps++;
if (steps < 2)
{
return true;
}

task.SetResult(steps);
return false;
}));
Expand Down Expand Up @@ -604,7 +607,9 @@ public void MockBounds()
args.PropertyName == View.YProperty.PropertyName ||
args.PropertyName == View.WidthProperty.PropertyName ||
args.PropertyName == View.HeightProperty.PropertyName)
{
changed = true;
}
};

view.SizeChanged += (sender, args) => changed = true;
Expand Down Expand Up @@ -671,7 +676,10 @@ public void HeightRequestEffectsGetSizeRequest()
MockPlatformSizeService.Current.GetPlatformSizeFunc = (ve, widthConstraint, heightConstraint) =>
{
if (heightConstraint < 30)
{
return new SizeRequest(new Size(40, 50));
}

return new SizeRequest(new Size(20, 100));
};

Expand Down

0 comments on commit ad7192d

Please sign in to comment.