-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathNavigatingFromEventArgsExtensionsTests.cs
More file actions
78 lines (63 loc) · 2.97 KB
/
NavigatingFromEventArgsExtensionsTests.cs
File metadata and controls
78 lines (63 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.UnitTests.Mocks;
using Xunit;
namespace CommunityToolkit.Maui.UnitTests.Extensions;
public class NavigatingFromEventArgsExtensionsTests : BaseViewTest
{
[Fact]
public async Task NavigatingFromEventArgsExtensions_IsDestinationPageACommunityToolkitPopupPage_ShouldReturnTrue()
{
// Arrange
MockApplication application = (MockApplication)ServiceProvider.GetRequiredService<IApplication>();
IPopupService popupService = ServiceProvider.GetRequiredService<IPopupService>();
Shell shell = (Shell)(application.Windows[0].Page ?? throw new InvalidOperationException("Unable to retrieve Shell"));
Page mainPage = shell.CurrentPage;
ShellContentPage shellContentPage = new();
Dictionary<string, object> shellParameters = new()
{
{ nameof(ContentPage.BackgroundColor), Colors.Orange }
};
TaskCompletionSource<bool?> isDestinationPageACommunityToolkitPopupPageTCS = new();
shellContentPage.NavigatingFromEventArgsReceived += (sender, args) =>
{
isDestinationPageACommunityToolkitPopupPageTCS.SetResult(args.IsDestinationPageACommunityToolkitPopupPage());
};
// Act
await mainPage.Navigation.PushAsync(shellContentPage);
await popupService.ShowPopupAsync<ShortLivedMockPageViewModel>(shell, null, shellParameters, TestContext.Current.CancellationToken);
bool? isDestinationPageACommunityToolkitPopupPage = await isDestinationPageACommunityToolkitPopupPageTCS.Task;
// Assert
Assert.True(isDestinationPageACommunityToolkitPopupPage);
}
[Fact]
public async Task NavigatingFromEventArgsExtensions_IsDestinationPageACommunityToolkitPopupPage_ShouldReturnFalse()
{
// Arrange
MockApplication application = (MockApplication)ServiceProvider.GetRequiredService<IApplication>();
IPopupService popupService = ServiceProvider.GetRequiredService<IPopupService>();
Shell shell = (Shell)(application.Windows[0].Page ?? throw new InvalidOperationException("Unable to retrieve Shell"));
Page mainPage = shell.CurrentPage;
ShellContentPage shellContentPage = new();
ShellContentPage anotherShellContentPage = new();
TaskCompletionSource<bool?> isDestinationPageACommunityToolkitPopupPageTCS = new();
shellContentPage.NavigatingFromEventArgsReceived += (sender, args) =>
{
isDestinationPageACommunityToolkitPopupPageTCS.SetResult(args.IsDestinationPageACommunityToolkitPopupPage());
};
// Act
await mainPage.Navigation.PushAsync(shellContentPage);
await mainPage.Navigation.PushAsync(anotherShellContentPage);
bool? isDestinationPageACommunityToolkitPopupPage = await isDestinationPageACommunityToolkitPopupPageTCS.Task;
// Assert
Assert.False(isDestinationPageACommunityToolkitPopupPage);
}
sealed class ShellContentPage : ContentPage
{
public event EventHandler<NavigatingFromEventArgs>? NavigatingFromEventArgsReceived;
protected override void OnNavigatingFrom(NavigatingFromEventArgs args)
{
base.OnNavigatingFrom(args);
NavigatingFromEventArgsReceived?.Invoke(this, args);
}
}
}