From d97814893938c07b293dfdc802b434be69fc83fa Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Thu, 19 Jun 2025 13:59:01 +0100 Subject: [PATCH 01/10] Remove exception swallowing and update tests to exhibit expected behaviour --- .../BaseHandlerTest.cs | 9 +- .../Extensions/PopupExtensionsTests.cs | 64 +++--- .../ServiceCollectionExtensionsTests.cs | 95 ++++----- .../Mocks/MockDispatcher.cs | 9 +- .../Mocks/MockPageViewModel.cs | 8 + .../Services/PopupServiceTests.cs | 187 +++++++++++------- .../Services/PopupService.shared.cs | 11 -- 7 files changed, 217 insertions(+), 166 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs index 5c0cd45d84..28437ec4a1 100644 --- a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs +++ b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs @@ -76,11 +76,10 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service #endregion #region Register Services for PopupServiceTests - - var mockPageViewModel = new MockPageViewModel(); - var mockPopup = new MockSelfClosingPopup(mockPageViewModel, new()); - - PopupService.AddPopup(mockPopup, mockPageViewModel, appBuilder.Services, ServiceLifetime.Transient); + + appBuilder.Services.AddTransientPopup(); + appBuilder.Services.AddTransientPopup(); + appBuilder.Services.AddTransientPopup(); #endregion diff --git a/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs b/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs index 45f0907a86..ee74f92c61 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs @@ -124,7 +124,7 @@ public async Task ClosePopupT_NullNavigation_ShouldThrowArgumentNullException() public async Task ShowPopupAsync_WithPopupType_ShowsPopupAndClosesPopup() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act navigation.ShowPopup(selfClosingPopup); @@ -228,7 +228,7 @@ public void ShowPopupAsync_Shell_WithViewType_ShowsPopup() public async Task ShowPopupAsync_AwaitingShowPopupAsync_EnsurePreviousPopupClosed() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); @@ -249,7 +249,7 @@ public async Task ShowPopupAsync_Shell_AwaitingShowPopupAsync_EnsurePreviousPopu Application.Current.Windows[0].Page = shell; var shellNavigation = Shell.Current.Navigation; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act await shell.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken); @@ -264,7 +264,7 @@ public async Task ShowPopupAsync_Shell_AwaitingShowPopupAsync_EnsurePreviousPopu public void ShowPopup_NavigationModalStackCountIncreases() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); Assert.Empty(navigation.ModalStack); // Act @@ -345,7 +345,7 @@ public void ShowPopupWithView_Shell_NavigationModalStackCountIncreases() public void ShowPopup_MultiplePopupsDisplayed() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act navigation.ShowPopup(selfClosingPopup, PopupOptions.Empty); @@ -359,7 +359,7 @@ public void ShowPopup_MultiplePopupsDisplayed() public void ShowPopup_Shell_MultiplePopupsDisplayed() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var shell = new Shell(); shell.Items.Add(new MockPage(new MockPageViewModel())); @@ -421,7 +421,7 @@ public void ShowPopupAsync_WithCustomOptions_AppliesOptions() // Arrange var onTappingOutsideOfPopup = () => { }; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var options = new PopupOptions { PageOverlayColor = Colors.Red, @@ -493,7 +493,7 @@ public void ShowPopupAsync_Shell_WithCustomOptions_AppliesOptions() var shellNavigation = Shell.Current.Navigation; var onTappingOutsideOfPopup = () => { }; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var options = new PopupOptions { PageOverlayColor = Colors.Red, @@ -713,7 +713,7 @@ public void ShowPopupAsyncWithView_Shell_WithCustomOptions_AppliesOptions() public async Task ShowPopupAsync_CancellationTokenExpired() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); // Act @@ -734,7 +734,7 @@ public async Task ShowPopupAsync_Shell_CancellationTokenExpired() Application.Current.Windows[0].Page = shell; var shellNavigation = Shell.Current.Navigation; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); @@ -788,7 +788,7 @@ public async Task ShowPopupAsyncWithView_Shell_CancellationTokenExpired() public async Task ShowPopupAsync_CancellationTokenCanceled() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); // Act @@ -809,7 +809,7 @@ public async Task ShowPopupAsync_Shell_CancellationTokenCanceled() Application.Current.Windows[0].Page = shell; var shellNavigation = Shell.Current.Navigation; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1)); @@ -863,15 +863,15 @@ public async Task ShowPopupAsyncWithView_Shell_CancellationTokenCanceled() public async Task ShowPopupAsync_ShouldValidateProperBindingContext() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); - var popupInstance = ServiceProvider.GetRequiredService(); - var popupViewModel = ServiceProvider.GetRequiredService(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var popupInstance = ServiceProvider.GetRequiredService(); // Act await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); // Assert - Assert.Same(popupInstance.BindingContext, popupViewModel); + Assert.NotNull(popupInstance.BindingContext); + Assert.IsType(popupInstance.BindingContext); } [Fact(Timeout = (int)TestDuration.Medium)] @@ -885,15 +885,15 @@ public async Task ShowPopupAsync_Shell_ShouldValidateProperBindingContext() Application.Current.Windows[0].Page = shell; var shellNavigation = Shell.Current.Navigation; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); - var popupInstance = ServiceProvider.GetRequiredService(); - var popupViewModel = ServiceProvider.GetRequiredService(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var popupInstance = ServiceProvider.GetRequiredService(); // Act await shell.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken); // Assert - Assert.Same(popupInstance.BindingContext, popupViewModel); + Assert.NotNull(popupInstance.BindingContext); + Assert.IsType(popupInstance.BindingContext); Assert.Equal(shellParameterBackgroundColorValue, selfClosingPopup.BackgroundColor); } @@ -902,8 +902,7 @@ public async Task ShowPopupAsyncWithView_ShouldValidateProperBindingContext() { // Arrange var view = new Grid(); - var popupInstance = ServiceProvider.GetRequiredService(); - var popupViewModel = ServiceProvider.GetRequiredService(); + var popupInstance = ServiceProvider.GetRequiredService(); // Act var showPopupTask = navigation.ShowPopupAsync(view, PopupOptions.Empty, TestContext.Current.CancellationToken); @@ -914,7 +913,8 @@ public async Task ShowPopupAsyncWithView_ShouldValidateProperBindingContext() await showPopupTask; // Assert - Assert.Same(popupInstance.BindingContext, popupViewModel); + Assert.NotNull(popupInstance.BindingContext); + Assert.IsType(popupInstance.BindingContext); } [Fact(Timeout = (int)TestDuration.Medium)] @@ -929,8 +929,7 @@ public async Task ShowPopupAsyncWithView_Shell_ShouldValidateProperBindingContex var shellNavigation = Shell.Current.Navigation; var view = new ViewWithIQueryAttributable(new ViewModelWithIQueryAttributable()); - var popupInstance = ServiceProvider.GetRequiredService(); - var popupViewModel = ServiceProvider.GetRequiredService(); + var popupInstance = ServiceProvider.GetRequiredService(); // Act var showPopupTask = shell.ShowPopupAsync(view, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken); @@ -941,7 +940,8 @@ public async Task ShowPopupAsyncWithView_Shell_ShouldValidateProperBindingContex await showPopupTask; // Assert - Assert.Same(popupInstance.BindingContext, popupViewModel); + Assert.NotNull(popupInstance.BindingContext); + Assert.IsType(popupInstance.BindingContext); Assert.Equal(shellParameterBackgroundColorValue, view.BackgroundColor); Assert.Equal(shellParameterViewModelTextValue, view.BindingContext.Text); } @@ -950,8 +950,8 @@ public async Task ShowPopupAsyncWithView_Shell_ShouldValidateProperBindingContex public async Task ShowPopupAsync_ShouldReturnResultOnceClosed() { // Arrange - var mockPopup = ServiceProvider.GetRequiredService(); - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var mockPopup = ServiceProvider.GetRequiredService(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act var result = await navigation.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken); @@ -972,8 +972,8 @@ public async Task ShowPopupAsync_Shell_ShouldReturnResultOnceClosed() Application.Current.Windows[0].Page = shell; var shellNavigation = Shell.Current.Navigation; - var mockPopup = ServiceProvider.GetRequiredService(); - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var mockPopup = ServiceProvider.GetRequiredService(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act var result = await shell.ShowPopupAsync(selfClosingPopup, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken); @@ -1070,7 +1070,7 @@ public async Task ShowPopupAsync_Shell_ShouldThrowArgumentNullException_WhenView public async Task ShowPopupAsync_ShouldThrowArgumentNullException_WhenNavigationIsNull() { // Arrange - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act / Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. @@ -1089,7 +1089,7 @@ public async Task ShowPopupAsync_Shell_ShouldThrowArgumentNullException_WhenNavi Application.Current.Windows[0].Page = shell; var shellNavigation = Shell.Current.Navigation; - var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); + var selfClosingPopup = ServiceProvider.GetRequiredService() ?? throw new InvalidOperationException(); // Act/Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. diff --git a/src/CommunityToolkit.Maui.UnitTests/Extensions/ServiceCollectionExtensionsTests.cs b/src/CommunityToolkit.Maui.UnitTests/Extensions/ServiceCollectionExtensionsTests.cs index c8babaf1ce..0968c02cc8 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Extensions/ServiceCollectionExtensionsTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Extensions/ServiceCollectionExtensionsTests.cs @@ -8,8 +8,9 @@ public class ServiceCollectionExtensionsTests : BaseTest { const string customRoute = "//MockCustomRoute"; readonly Type mockPageType = typeof(MockPage); - readonly Type mockPopupType = typeof(MockSelfClosingPopup); - readonly Type mockViewModelType = typeof(MockPageViewModel); + readonly Type mockPageViewModelType = typeof(MockPageViewModel); + readonly Type mockPopupType = typeof(ShortLivedSelfClosingPopup); + readonly Type mockPopupViewModelType = typeof(ShortLivedMockPageViewModel); [Fact] public void IServiceCollection_VerifyTransientPopup() @@ -41,12 +42,12 @@ public void IServiceCollection_VerifyTransientPopupWithViewModel() const ServiceLifetime expectedServiceLifetime = ServiceLifetime.Transient; // Act - services.AddTransientPopup(); + services.AddTransientPopup(); var serviceProvider = services.BuildServiceProvider(); // Assert var mockPopupServiceDescriptor = services.Single(s => s.ServiceType == mockPopupType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPopupViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPopupServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -55,13 +56,13 @@ public void IServiceCollection_VerifyTransientPopupWithViewModel() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPopupType, mockPopupServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPopupViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPopupType, mockPopupServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPopupViewModelType, mockViewModelServiceDescriptor.ImplementationType); - Assert.IsType(serviceProvider.GetRequiredService()); - Assert.IsType(serviceProvider.GetRequiredService()); + Assert.IsType(serviceProvider.GetRequiredService()); + Assert.IsType(serviceProvider.GetRequiredService()); } [Fact] @@ -77,7 +78,7 @@ public void IServiceCollection_VerifyTransient() // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -86,10 +87,10 @@ public void IServiceCollection_VerifyTransient() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -109,7 +110,7 @@ public void IServiceCollection_VerifyTransientShellRouteWithRouteParam() // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -120,10 +121,10 @@ public void IServiceCollection_VerifyTransientShellRouteWithRouteParam() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -144,7 +145,7 @@ public void IServiceCollection_VerifyTransientShellRouteWithRouteAndRouteFactory // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -155,10 +156,10 @@ public void IServiceCollection_VerifyTransientShellRouteWithRouteAndRouteFactory Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -195,12 +196,12 @@ public void IServiceCollection_VerifySingletonPopupWithViewModel() var services = MauiApp.CreateBuilder().Services; // Act - services.AddSingletonPopup(); + services.AddSingletonPopup(); var serviceProvider = services.BuildServiceProvider(); // Assert var mockPopupServiceDescriptor = services.Single(s => s.ServiceType == mockPopupType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPopupViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPopupServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -209,13 +210,13 @@ public void IServiceCollection_VerifySingletonPopupWithViewModel() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPopupType, mockPopupServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPopupViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPopupType, mockPopupServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPopupViewModelType, mockViewModelServiceDescriptor.ImplementationType); - Assert.IsType(serviceProvider.GetRequiredService()); - Assert.IsType(serviceProvider.GetRequiredService()); + Assert.IsType(serviceProvider.GetRequiredService()); + Assert.IsType(serviceProvider.GetRequiredService()); } [Fact] @@ -231,7 +232,7 @@ public void IServiceCollection_VerifySingleton() // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -240,10 +241,10 @@ public void IServiceCollection_VerifySingleton() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -263,7 +264,7 @@ public void IServiceCollection_VerifySingletonShellRouteWithRouteParam() // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -274,10 +275,10 @@ public void IServiceCollection_VerifySingletonShellRouteWithRouteParam() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -298,7 +299,7 @@ public void IServiceCollection_VerifySingletonShellRouteWithRouteAndRouteFactory // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -309,10 +310,10 @@ public void IServiceCollection_VerifySingletonShellRouteWithRouteAndRouteFactory Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -350,12 +351,12 @@ public void IServiceCollection_VerifyScopedPopupWithViewModel() var services = MauiApp.CreateBuilder().Services; // Act - services.AddScopedPopup(); + services.AddScopedPopup(); var serviceProvider = services.BuildServiceProvider(); // Assert var mockPopupServiceDescriptor = services.Single(s => s.ServiceType == mockPopupType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPopupViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPopupServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -364,13 +365,13 @@ public void IServiceCollection_VerifyScopedPopupWithViewModel() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPopupType, mockPopupServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPopupViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPopupType, mockPopupServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPopupViewModelType, mockViewModelServiceDescriptor.ImplementationType); - Assert.IsType(serviceProvider.GetRequiredService()); - Assert.IsType(serviceProvider.GetRequiredService()); + Assert.IsType(serviceProvider.GetRequiredService()); + Assert.IsType(serviceProvider.GetRequiredService()); } [Fact] @@ -386,7 +387,7 @@ public void IServiceCollection_VerifyScoped() // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -395,10 +396,10 @@ public void IServiceCollection_VerifyScoped() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -418,7 +419,7 @@ public void IServiceCollection_VerifyScopedShellRouteWithRouteParam() // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -429,10 +430,10 @@ public void IServiceCollection_VerifyScopedShellRouteWithRouteParam() Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); @@ -453,7 +454,7 @@ public void IServiceCollection_VerifyScopedShellRouteWithRouteAndRouteFactoryPar // Assert var mockPageServiceDescriptor = services.Single(s => s.ServiceType == mockPageType && s.Lifetime.Equals(expectedServiceLifetime)); - var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); + var mockViewModelServiceDescriptor = services.Single(s => s.ServiceType == mockPageViewModelType && s.Lifetime.Equals(expectedServiceLifetime)); Assert.NotNull(mockPageServiceDescriptor); Assert.NotNull(mockViewModelServiceDescriptor); @@ -464,10 +465,10 @@ public void IServiceCollection_VerifyScopedShellRouteWithRouteAndRouteFactoryPar Assert.Equal(expectedServiceLifetime, mockViewModelServiceDescriptor.Lifetime); Assert.Equal(mockPageType, mockPageServiceDescriptor.ServiceType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ServiceType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ServiceType); Assert.Equal(mockPageType, mockPageServiceDescriptor.ImplementationType); - Assert.Equal(mockViewModelType, mockViewModelServiceDescriptor.ImplementationType); + Assert.Equal(mockPageViewModelType, mockViewModelServiceDescriptor.ImplementationType); Assert.IsType(serviceProvider.GetRequiredService()); Assert.IsType(serviceProvider.GetRequiredService()); diff --git a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs index f6232975fe..3b9d3eed8e 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs @@ -22,7 +22,14 @@ public bool Dispatch(Action action) public bool DispatchDelayed(TimeSpan delay, Action action) { - return false; + Task.Run(async () => + { + await Task.Delay(delay); + + action(); + }); + + return true; } sealed class DispatcherTimerStub : IDispatcherTimer, IDisposable diff --git a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockPageViewModel.cs b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockPageViewModel.cs index 86c172c51b..0cda5e8794 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockPageViewModel.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockPageViewModel.cs @@ -5,4 +5,12 @@ namespace CommunityToolkit.Maui.UnitTests.Mocks; public class MockPageViewModel : BindableObject { public bool HasLoaded { get; set; } +} + +public class LongLivedMockPageViewModel : MockPageViewModel +{ +} + +public class ShortLivedMockPageViewModel : MockPageViewModel +{ } \ No newline at end of file diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index e4abe072d5..9c21f17100 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Diagnostics; using CommunityToolkit.Maui.Services; using CommunityToolkit.Maui.UnitTests.Mocks; using CommunityToolkit.Maui.Views; @@ -25,120 +26,136 @@ public void AddPopup_RegistersViewInServiceCollection() { // Arrange var services = new ServiceCollection(); - + // Act PopupService.AddPopup(services, ServiceLifetime.Transient); - + // Assert var serviceDescriptor = Assert.Single(services); Assert.Equal(typeof(MockPopup), serviceDescriptor.ServiceType); Assert.Equal(ServiceLifetime.Transient, serviceDescriptor.Lifetime); } - + [Fact] public void AddPopup_WithViewModel_RegistersBothViewAndViewModel() { // Arrange var services = new ServiceCollection(); - + // Act PopupService.AddPopup(services, ServiceLifetime.Transient); - + // Assert Assert.Equal(2, services.Count); Assert.Contains(services, sd => sd.ServiceType == typeof(MockPopup)); Assert.Contains(services, sd => sd.ServiceType == typeof(PopupViewModel)); } - + [Fact] public void ShowPopupAsync_UsingNavigation_WithViewType_ShowsPopup() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + // Act - popupService.ShowPopup(navigation); - + popupService.ShowPopup(navigation); + // Assert Assert.Single(navigation.ModalStack); Assert.IsType(navigation.ModalStack[0]); } + + public class AsynchronousPopupTest + { + readonly TimeSpan waitTime; + public AsynchronousPopupTest(Action action, TimeSpan waitTime) + { + this.waitTime = waitTime; + action.Invoke(); + } + + public async Task WaitUntilCompleted() + { + await Task.Delay(waitTime, TestContext.Current.CancellationToken); + } + } + [Fact] public void ShowPopupAsync_UsingPage_WithViewType_ShowsPopup() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + if (Application.Current?.Windows[0].Page is not Page page) { throw new InvalidOperationException("Page cannot be null"); } - + // Act - popupService.ShowPopup(page); - + popupService.ShowPopup(page); + // Assert Assert.Single(navigation.ModalStack); Assert.IsType(navigation.ModalStack[0]); } - + [Fact(Timeout = (int)TestDuration.Short)] public async Task ShowPopupAsync_AwaitingShowPopupAsync_EnsurePreviousPopupClosed() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + // Act - await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); - await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); - + await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); + await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); + // Assert Assert.Empty(navigation.ModalStack); } - + [Fact(Timeout = (int)TestDuration.Long)] public async Task ShowPopupAsync_UsingPage_AwaitingShowPopupAsync_EnsurePreviousPopupClosed() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + if (Application.Current?.Windows[0].Page is not Page page) { throw new InvalidOperationException("Page cannot be null"); } - + // Act - await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); - await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); - + await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); + await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); + // Assert Assert.Empty(navigation.ModalStack); } - + [Fact] public void ShowPopup_NavigationModalStackCountIncreases() { // Arrange var popupService = ServiceProvider.GetRequiredService(); Assert.Empty(navigation.ModalStack); - + // Act - popupService.ShowPopup(navigation, PopupOptions.Empty); - + popupService.ShowPopup(navigation, PopupOptions.Empty); + // Assert Assert.Single(navigation.ModalStack); } - [Fact] + [Fact(Timeout = (int)TestDuration.Short)] public void ShowPopup_MultiplePopupsDisplayed() { // Arrange var popupService = ServiceProvider.GetRequiredService(); // Act - popupService.ShowPopup(navigation, PopupOptions.Empty); - popupService.ShowPopup(navigation, PopupOptions.Empty); + popupService.ShowPopup(navigation, PopupOptions.Empty); + popupService.ShowPopup(navigation, PopupOptions.Empty); // Assert Assert.Equal(2, navigation.ModalStack.Count); @@ -160,9 +177,7 @@ public void ShowPopupAsync_WithCustomOptions_AppliesOptions() }; // Act - popupService.ShowPopup( - navigation, - options); + popupService.ShowPopup(navigation, options); var popupPage = (PopupPage)navigation.ModalStack[0]; var popupPageLayout = popupPage.Content; @@ -213,7 +228,7 @@ public async Task ShowPopupAsync_CancellationTokenExpired() } // Assert - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, cts.Token)); } [Fact(Timeout = (int)TestDuration.Short)] @@ -227,7 +242,7 @@ public async Task ShowPopupAsync_CancellationTokenCanceled() await cts.CancelAsync(); // Assert - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(navigation, PopupOptions.Empty, cts.Token)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync(navigation, PopupOptions.Empty, cts.Token)); } [Fact(Timeout = (int)TestDuration.Medium)] @@ -235,8 +250,7 @@ public async Task ShowPopupAsyncShouldValidateProperBindingContext() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - var popupInstance = ServiceProvider.GetRequiredService(); - var popupViewModel = ServiceProvider.GetRequiredService(); + var popupInstance = ServiceProvider.GetRequiredService(); if (Application.Current?.Windows[0].Page is not Page page) { @@ -244,18 +258,19 @@ public async Task ShowPopupAsyncShouldValidateProperBindingContext() } // Act - await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, TestContext.Current.CancellationToken); + await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, TestContext.Current.CancellationToken); // Assert - Assert.Same(popupInstance.BindingContext, popupViewModel); + Assert.NotNull(popupInstance.BindingContext); + Assert.IsType(popupInstance.BindingContext); } [Fact(Timeout = (int)TestDuration.Long)] public async Task ShowPopupAsyncShouldReturnResultOnceClosed() { // Arrange - var mockPopup = ServiceProvider.GetRequiredService(); + var mockPopup = ServiceProvider.GetRequiredService(); var popupService = ServiceProvider.GetRequiredService(); if (Application.Current?.Windows[0].Page is not Page page) @@ -264,7 +279,7 @@ public async Task ShowPopupAsyncShouldReturnResultOnceClosed() } // Act - var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); + var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); // Assert Assert.Same(mockPopup.Result, result.Result); @@ -283,7 +298,7 @@ public async Task ShowPopupTAsyncShouldReturnResultOnceClosed() } // Act - var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); + var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); // Assert Assert.False(result.WasDismissedByTappingOutsideOfPopup); @@ -297,7 +312,7 @@ public async Task ShowPopupAsync_UsingNavigation_ShouldThrowArgumentNullExceptio // Act // Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((INavigation?)null, PopupOptions.Empty, CancellationToken.None)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((INavigation?)null, PopupOptions.Empty, CancellationToken.None)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -309,7 +324,7 @@ public async Task ShowPopupAsync_UsingPage_ShouldThrowArgumentNullException_When // Act // Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((Page?)null, PopupOptions.Empty, CancellationToken.None)); + await Assert.ThrowsAsync(() => popupService.ShowPopupAsync((Page?)null, PopupOptions.Empty, CancellationToken.None)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -322,7 +337,7 @@ public void ShowPopup_UsingPage_ShouldThrowArgumentNullException_WhenNavigationI // Act // Assert #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. - Assert.Throws(() => popupService.ShowPopup((Page?)null, PopupOptions.Empty)); + Assert.Throws(() => popupService.ShowPopup((Page?)null, PopupOptions.Empty)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. } @@ -397,7 +412,7 @@ public async Task ShowPopupAsync_ShouldReturnDefaultResult_WhenPopupIsClosedWith { // Arrange var popupService = ServiceProvider.GetRequiredService(); - var mockPopup = ServiceProvider.GetRequiredService(); + var mockPopup = ServiceProvider.GetRequiredService(); if (Application.Current?.Windows[0].Page is not Page page) { @@ -405,7 +420,7 @@ public async Task ShowPopupAsync_ShouldReturnDefaultResult_WhenPopupIsClosedWith } // Act - var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); + var result = await popupService.ShowPopupAsync(page.Navigation, PopupOptions.Empty, CancellationToken.None); // Assert Assert.Equal(mockPopup.Result, result.Result); @@ -522,43 +537,75 @@ public async Task ClosePopupAsyncT_ShouldClosePopupUsingPageAndReturnResult() } } -sealed class MockSelfClosingPopup : Popup, IQueryAttributable +class LongLivedSelfClosingPopup : MockSelfClosingPopup { - public const int ExpectedResult = 2; + public LongLivedSelfClosingPopup(LongLivedMockPageViewModel viewModel) + : base(viewModel, TimeSpan.FromMilliseconds(1500), "Long Lived") + { + } +} - public MockSelfClosingPopup(MockPageViewModel viewModel, object? result = null) +class ShortLivedSelfClosingPopup : MockSelfClosingPopup +{ + public ShortLivedSelfClosingPopup(ShortLivedMockPageViewModel viewModel) + : base(viewModel, TimeSpan.FromMilliseconds(500), "Short Lived") + { + } +} + +#pragma warning disable CA1001 +class MockSelfClosingPopup : Popup, IQueryAttributable +#pragma warning restore CA1001 +{ + internal TimeSpan DisplayDuration { get; } + + public MockSelfClosingPopup(MockPageViewModel viewModel, TimeSpan displayDuration, object? result = null) { BackgroundColor = DefaultBackgroundColor; BindingContext = viewModel; + DisplayDuration = displayDuration; Result = result; Opened += HandlePopupOpened; + Closed += HandlePopupClosed; } + + CancellationTokenSource? cancellationTokenSource; public static Color DefaultBackgroundColor { get; } = Colors.White; + void HandlePopupClosed(object? sender, EventArgs e) + { + cancellationTokenSource?.Cancel(); + } + void HandlePopupOpened(object? sender, EventArgs e) { - var timer = Dispatcher.CreateTimer(); - timer.Interval = TimeSpan.FromMilliseconds(500); - timer.Tick += HandleTick; - timer.Start(); + cancellationTokenSource?.Cancel(); + + cancellationTokenSource = new CancellationTokenSource(); + + Console.WriteLine($"{DateTime.Now:O} HandlePopupOpened {BindingContext.GetType().Name}"); - async void HandleTick(object? sender, EventArgs e) - { - timer.Tick -= HandleTick; - try + Dispatcher.DispatchDelayed( + DisplayDuration, + async () => { - await CloseAsync(Result); - } - catch (InvalidOperationException) - { - // If test has already ended, Popup.CloseAsync will throw an InvalidOperationException - // because all Popups are removed from ModalStack in BaseHandlerTest.DisposeAsyncCore() - } - } - } - - public object? Result { get; } = ExpectedResult; + if (cancellationTokenSource?.IsCancellationRequested is true) + { + return; + } + + Console.WriteLine( + $"{DateTime.Now:O} Closing {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}"); + + await CloseAsync(Result, cancellationTokenSource?.Token ?? CancellationToken.None); + + Console.WriteLine( + $"{DateTime.Now:O} Closed {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}"); + }); + } + + public object? Result { get; } void IQueryAttributable.ApplyQueryAttributes(IDictionary query) { diff --git a/src/CommunityToolkit.Maui/Services/PopupService.shared.cs b/src/CommunityToolkit.Maui/Services/PopupService.shared.cs index a72243d25d..8506fefb5e 100644 --- a/src/CommunityToolkit.Maui/Services/PopupService.shared.cs +++ b/src/CommunityToolkit.Maui/Services/PopupService.shared.cs @@ -178,17 +178,6 @@ public Task> ClosePopupAsync(INavigation navigation, T result services.TryAdd(new ServiceDescriptor(typeof(TPopupViewModel), typeof(TPopupViewModel), lifetime)); } - internal static void AddPopup<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TPopupView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TPopupViewModel> - (TPopupView popup, TPopupViewModel viewModel, IServiceCollection services, ServiceLifetime lifetime) - where TPopupView : IView - where TPopupViewModel : notnull - { - viewModelToViewMappings.TryAdd(typeof(TPopupViewModel), typeof(TPopupView)); - - services.TryAdd(new ServiceDescriptor(typeof(TPopupView), _ => popup, lifetime)); - services.TryAdd(new ServiceDescriptor(typeof(TPopupViewModel), _ => viewModel, lifetime)); - } - View GetPopupContent(T bindingContext) { if (bindingContext is View view) From f43439292d4938b5553c964ac4a4ea389e966f8d Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:04:03 +0100 Subject: [PATCH 02/10] Remove leftover debugging class --- .../Services/PopupServiceTests.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index 9c21f17100..08b34b8645 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -65,22 +65,6 @@ public void ShowPopupAsync_UsingNavigation_WithViewType_ShowsPopup() Assert.IsType(navigation.ModalStack[0]); } - public class AsynchronousPopupTest - { - readonly TimeSpan waitTime; - - public AsynchronousPopupTest(Action action, TimeSpan waitTime) - { - this.waitTime = waitTime; - action.Invoke(); - } - - public async Task WaitUntilCompleted() - { - await Task.Delay(waitTime, TestContext.Current.CancellationToken); - } - } - [Fact] public void ShowPopupAsync_UsingPage_WithViewType_ShowsPopup() { From d4613bbfa369680af1684cb4a2ec8db7d77dcf46 Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:04:35 +0100 Subject: [PATCH 03/10] Remove unused using --- .../Services/PopupServiceTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index 08b34b8645..5a7f33f506 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using System.Diagnostics; using CommunityToolkit.Maui.Services; using CommunityToolkit.Maui.UnitTests.Mocks; using CommunityToolkit.Maui.Views; From 174ba01d00d844fafe5415e365122943c8ad54c2 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:30:11 -0700 Subject: [PATCH 04/10] Use `ThrowsAnyAsync` --- .../Layouts/StateContainerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs b/src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs index 323efa55ba..e23fdc9cf8 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs @@ -241,7 +241,7 @@ public async Task StateContainer_CustomAnimation_Timeout() var cancelledTokenSource = new CancellationTokenSource(TimeSpan.FromMicroseconds(1)); await Task.Delay(10, TestContext.Current.CancellationToken); - await Assert.ThrowsAsync(() => StateContainer.ChangeStateWithAnimation(layout, StateKey.Error, beforeStateChangeAnimation, afterStateChangeAnimation, cancelledTokenSource.Token)); + await Assert.ThrowsAnyAsync(() => StateContainer.ChangeStateWithAnimation(layout, StateKey.Error, beforeStateChangeAnimation, afterStateChangeAnimation, cancelledTokenSource.Token)); } [Fact(Timeout = (int)TestDuration.Long)] From 9699095787332afad0a8e2058f08b667b8a0a9e6 Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Fri, 20 Jun 2025 21:17:41 +0100 Subject: [PATCH 05/10] Refactorings based on code review suggestions --- .../Mocks/MockDispatcher.cs | 9 ++-- .../Services/PopupServiceTests.cs | 42 +++++++++---------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs index 3b9d3eed8e..797ef93a91 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs @@ -22,12 +22,9 @@ public bool Dispatch(Action action) public bool DispatchDelayed(TimeSpan delay, Action action) { - Task.Run(async () => - { - await Task.Delay(delay); - - action(); - }); + Thread.Sleep(delay); + + action(); return true; } diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index 5a7f33f506..40e48d27a8 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -561,31 +561,31 @@ void HandlePopupClosed(object? sender, EventArgs e) cancellationTokenSource?.Cancel(); } - void HandlePopupOpened(object? sender, EventArgs e) + async void HandlePopupOpened(object? sender, EventArgs e) { - cancellationTokenSource?.Cancel(); - + if (cancellationTokenSource is not null) + { + await cancellationTokenSource.CancelAsync(); + } + cancellationTokenSource = new CancellationTokenSource(); - + Console.WriteLine($"{DateTime.Now:O} HandlePopupOpened {BindingContext.GetType().Name}"); - Dispatcher.DispatchDelayed( - DisplayDuration, - async () => - { - if (cancellationTokenSource?.IsCancellationRequested is true) - { - return; - } - - Console.WriteLine( - $"{DateTime.Now:O} Closing {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}"); - - await CloseAsync(Result, cancellationTokenSource?.Token ?? CancellationToken.None); - - Console.WriteLine( - $"{DateTime.Now:O} Closed {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}"); - }); + await Task.Delay(DisplayDuration); + + if (cancellationTokenSource?.IsCancellationRequested is true) + { + return; + } + + Console.WriteLine( + $"{DateTime.Now:O} Closing {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}"); + + await CloseAsync(Result, cancellationTokenSource?.Token ?? CancellationToken.None); + + Console.WriteLine( + $"{DateTime.Now:O} Closed {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}"); } public object? Result { get; } From d479d568441bf372d3698a193e485aba90ea92f7 Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Fri, 20 Jun 2025 21:18:42 +0100 Subject: [PATCH 06/10] Remove timeout --- .../Services/PopupServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index c39ea3c814..8e8d88ac09 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -130,7 +130,7 @@ public void ShowPopup_NavigationModalStackCountIncreases() Assert.Single(navigation.ModalStack); } - [Fact(Timeout = (int)TestDuration.Short)] + [Fact] public void ShowPopup_MultiplePopupsDisplayed() { // Arrange From 84b12593bceb6cee5cefce755f435240b4d77c87 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Sun, 22 Jun 2025 15:38:42 -0700 Subject: [PATCH 07/10] Fix Merge Conflicts --- .../BaseHandlerTest.cs | 2 +- .../Services/PopupServiceTests.cs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs index 4d84ec251e..a622734110 100644 --- a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs +++ b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs @@ -81,7 +81,7 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service appBuilder.Services.AddTransientPopup(); appBuilder.Services.AddTransientPopup(); - appBuilder.Services.AddTransient(); + appBuilder.Services.AddTransient(); #endregion var mauiApp = appBuilder.Build(); diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index 41a48fe7cf..211b9a5dac 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -523,7 +523,19 @@ public async Task ClosePopupAsyncT_ShouldClosePopupUsingPageAndReturnResult() class GarbageCollectionHeavySelfClosingPopup(MockPageViewModel viewModel, object? result = null) : MockSelfClosingPopup(viewModel, TimeSpan.FromMilliseconds(500), result) { - + protected override void HandlePopupOpened(object? sender, EventArgs e) + { + GC.Collect(); // Run Garbage Collection before closing the popup + + base.HandlePopupOpened(sender, e); // Closes the popup + } + + protected override void HandlePopupClosed(object? sender, EventArgs e) + { + base.HandlePopupClosed(sender, e); + + GC.Collect(); // Run Garbage collection again after closing the Popup + } } class LongLivedSelfClosingPopup : MockSelfClosingPopup @@ -562,7 +574,7 @@ public MockSelfClosingPopup(MockPageViewModel viewModel, TimeSpan displayDuratio public static Color DefaultBackgroundColor { get; } = Colors.White; - void HandlePopupClosed(object? sender, EventArgs e) + protected virtual void HandlePopupClosed(object? sender, EventArgs e) { cancellationTokenSource?.Cancel(); } From 267cfa83b5851947366fd51cf7fc1c683a70825a Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Sun, 22 Jun 2025 15:41:23 -0700 Subject: [PATCH 08/10] `dotnet format` --- .../BaseHandlerTest.cs | 4 +- .../Mocks/MockDispatcher.cs | 2 +- .../Services/PopupServiceTests.cs | 54 +++++++++---------- .../AppThemeResourceExtension.shared.cs | 4 +- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs index a622734110..9ddf86d4bf 100644 --- a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs +++ b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs @@ -76,10 +76,10 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service #endregion #region Register Services for PopupServiceTests - + appBuilder.Services.AddTransientPopup(); appBuilder.Services.AddTransientPopup(); - + appBuilder.Services.AddTransientPopup(); appBuilder.Services.AddTransient(); #endregion diff --git a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs index 797ef93a91..2b13879410 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs @@ -25,7 +25,7 @@ public bool DispatchDelayed(TimeSpan delay, Action action) Thread.Sleep(delay); action(); - + return true; } diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index 211b9a5dac..cfc1fcf0aa 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -25,107 +25,107 @@ public void AddPopup_RegistersViewInServiceCollection() { // Arrange var services = new ServiceCollection(); - + // Act PopupService.AddPopup(services, ServiceLifetime.Transient); - + // Assert var serviceDescriptor = Assert.Single(services); Assert.Equal(typeof(MockPopup), serviceDescriptor.ServiceType); Assert.Equal(ServiceLifetime.Transient, serviceDescriptor.Lifetime); } - + [Fact] public void AddPopup_WithViewModel_RegistersBothViewAndViewModel() { // Arrange var services = new ServiceCollection(); - + // Act PopupService.AddPopup(services, ServiceLifetime.Transient); - + // Assert Assert.Equal(2, services.Count); Assert.Contains(services, sd => sd.ServiceType == typeof(MockPopup)); Assert.Contains(services, sd => sd.ServiceType == typeof(PopupViewModel)); } - + [Fact] public void ShowPopupAsync_UsingNavigation_WithViewType_ShowsPopup() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + // Act popupService.ShowPopup(navigation); - + // Assert Assert.Single(navigation.ModalStack); Assert.IsType(navigation.ModalStack[0]); } - + [Fact] public void ShowPopupAsync_UsingPage_WithViewType_ShowsPopup() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + if (Application.Current?.Windows[0].Page is not Page page) { throw new InvalidOperationException("Page cannot be null"); } - + // Act popupService.ShowPopup(page); - + // Assert Assert.Single(navigation.ModalStack); Assert.IsType(navigation.ModalStack[0]); } - + [Fact(Timeout = (int)TestDuration.Short)] public async Task ShowPopupAsync_AwaitingShowPopupAsync_EnsurePreviousPopupClosed() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + // Act await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); await popupService.ShowPopupAsync(navigation, PopupOptions.Empty, CancellationToken.None); - + // Assert Assert.Empty(navigation.ModalStack); } - + [Fact(Timeout = (int)TestDuration.Long)] public async Task ShowPopupAsync_UsingPage_AwaitingShowPopupAsync_EnsurePreviousPopupClosed() { // Arrange var popupService = ServiceProvider.GetRequiredService(); - + if (Application.Current?.Windows[0].Page is not Page page) { throw new InvalidOperationException("Page cannot be null"); } - + // Act await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); await popupService.ShowPopupAsync(page, PopupOptions.Empty, CancellationToken.None); - + // Assert Assert.Empty(navigation.ModalStack); } - + [Fact] public void ShowPopup_NavigationModalStackCountIncreases() { // Arrange var popupService = ServiceProvider.GetRequiredService(); Assert.Empty(navigation.ModalStack); - + // Act popupService.ShowPopup(navigation, PopupOptions.Empty); - + // Assert Assert.Single(navigation.ModalStack); } @@ -526,14 +526,14 @@ class GarbageCollectionHeavySelfClosingPopup(MockPageViewModel viewModel, object protected override void HandlePopupOpened(object? sender, EventArgs e) { GC.Collect(); // Run Garbage Collection before closing the popup - + base.HandlePopupOpened(sender, e); // Closes the popup } protected override void HandlePopupClosed(object? sender, EventArgs e) { base.HandlePopupClosed(sender, e); - + GC.Collect(); // Run Garbage collection again after closing the Popup } } @@ -559,7 +559,7 @@ class MockSelfClosingPopup : Popup, IQueryAttributable #pragma warning restore CA1001 { internal TimeSpan DisplayDuration { get; } - + public MockSelfClosingPopup(MockPageViewModel viewModel, TimeSpan displayDuration, object? result = null) { BackgroundColor = DefaultBackgroundColor; @@ -569,7 +569,7 @@ public MockSelfClosingPopup(MockPageViewModel viewModel, TimeSpan displayDuratio Opened += HandlePopupOpened; Closed += HandlePopupClosed; } - + CancellationTokenSource? cancellationTokenSource; public static Color DefaultBackgroundColor { get; } = Colors.White; @@ -578,7 +578,7 @@ protected virtual void HandlePopupClosed(object? sender, EventArgs e) { cancellationTokenSource?.Cancel(); } - + protected virtual async void HandlePopupOpened(object? sender, EventArgs e) { if (cancellationTokenSource is not null) diff --git a/src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs b/src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs index c63cdb4b59..a4db4ff35c 100644 --- a/src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs +++ b/src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs @@ -52,7 +52,7 @@ public BindingBase ProvideValue(IServiceProvider serviceProvider) var rootProvider = serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider; var root = rootProvider?.RootObject; if (root is IResourcesProvider { IsResourcesCreated: true } rootResources - && rootResources.Resources.TryGetValue(Key, out resource)) + && rootResources.Resources.TryGetValue(Key, out resource)) { switch (resource) { @@ -93,7 +93,7 @@ static bool TryFindResourceInVisualElement(object element, string key, [NotNullW // If the element has a Resources property via IResourcesProvider if (element is IResourcesProvider { IsResourcesCreated: true } provider - && provider.Resources.TryGetValue(key, out resource)) + && provider.Resources.TryGetValue(key, out resource)) { return true; } From 9fb35eb2456e992761e10b5c687d5de7eaf39ff1 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Sun, 22 Jun 2025 15:44:31 -0700 Subject: [PATCH 09/10] Update formatting --- .../Services/PopupServiceTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs index cfc1fcf0aa..a49611ad43 100644 --- a/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs +++ b/src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs @@ -558,20 +558,19 @@ public ShortLivedSelfClosingPopup(ShortLivedMockPageViewModel viewModel) class MockSelfClosingPopup : Popup, IQueryAttributable #pragma warning restore CA1001 { - internal TimeSpan DisplayDuration { get; } + readonly TimeSpan displayDuration; + CancellationTokenSource? cancellationTokenSource; public MockSelfClosingPopup(MockPageViewModel viewModel, TimeSpan displayDuration, object? result = null) { + this.displayDuration = displayDuration; BackgroundColor = DefaultBackgroundColor; BindingContext = viewModel; - DisplayDuration = displayDuration; Result = result; Opened += HandlePopupOpened; Closed += HandlePopupClosed; } - CancellationTokenSource? cancellationTokenSource; - public static Color DefaultBackgroundColor { get; } = Colors.White; protected virtual void HandlePopupClosed(object? sender, EventArgs e) @@ -590,7 +589,7 @@ protected virtual async void HandlePopupOpened(object? sender, EventArgs e) Console.WriteLine($@"{DateTime.Now:O} HandlePopupOpened {BindingContext.GetType().Name}"); - await Task.Delay(DisplayDuration); + await Task.Delay(displayDuration); if (cancellationTokenSource?.IsCancellationRequested is true) { From 4892a371edb18d6998c045525b7798c7cdc0acaf Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Sun, 22 Jun 2025 15:52:44 -0700 Subject: [PATCH 10/10] Use `AddTransientPopup` --- src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs index 9ddf86d4bf..1a703d06cd 100644 --- a/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs +++ b/src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs @@ -79,9 +79,9 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service appBuilder.Services.AddTransientPopup(); appBuilder.Services.AddTransientPopup(); + appBuilder.Services.AddTransientPopup(); appBuilder.Services.AddTransientPopup(); - appBuilder.Services.AddTransient(); #endregion var mauiApp = appBuilder.Build();