|
1 | | -using Prism.DryIoc.Maui.Tests.Mocks.ViewModels; |
| 1 | +using Prism.DryIoc.Maui.Tests.Mocks.ViewModels; |
2 | 2 | using Prism.DryIoc.Maui.Tests.Mocks.Views; |
3 | 3 | using Prism.Navigation.Xaml; |
4 | 4 |
|
@@ -251,4 +251,39 @@ public async Task Region_IsDestroyed_OnNavigationGoBack() |
251 | 251 | var result = await navigationService.NavigateAsync("RegionPage"); |
252 | 252 | Assert.True(result.Success); |
253 | 253 | } |
| 254 | + |
| 255 | + [Fact] |
| 256 | + public void Issue3328_WhenNavigatingToUnregisteredView_ShouldFailWithKeyNotFoundException() |
| 257 | + { |
| 258 | + // Arrange |
| 259 | + var mauiApp = CreateBuilder(prism => prism.RegisterTypes(container => |
| 260 | + { |
| 261 | + container.RegisterForNavigation<MockContentRegionPage, MockContentRegionPageViewModel>(); |
| 262 | + container.RegisterForRegionNavigation<MockRegionViewA, MockRegionViewAViewModel>(); |
| 263 | + }).CreateWindow(nav => nav.NavigateAsync("MockContentRegionPage"))).Build(); |
| 264 | + var window = GetWindow(mauiApp); |
| 265 | + |
| 266 | + Assert.IsType<MockContentRegionPage>(window.Page); |
| 267 | + var page = window.Page as MockContentRegionPage; |
| 268 | + Assert.NotNull(page.ContentRegion.Content); |
| 269 | + Assert.IsType<MockRegionViewA>(page.ContentRegion.Content); |
| 270 | + Assert.IsType<MockRegionViewAViewModel>(page.ContentRegion.Content.BindingContext); |
| 271 | + |
| 272 | + // Act |
| 273 | + var regionManager = mauiApp.Services.GetRequiredService<IRegionManager>(); |
| 274 | + INavigationResult result = null; |
| 275 | + |
| 276 | + regionManager.RequestNavigate("ContentRegion", "UnregisteredRegion", navResult => |
| 277 | + { |
| 278 | + result = navResult; |
| 279 | + }); |
| 280 | + |
| 281 | + // Assert |
| 282 | + Assert.False(result.Success); |
| 283 | + var ex = Assert.IsType<KeyNotFoundException>(result.Exception); |
| 284 | + Assert.Equal("No view with the name 'UnregisteredRegion' has been registered", ex.Message); |
| 285 | + |
| 286 | + Assert.IsType<MockRegionViewA>(page.ContentRegion.Content); |
| 287 | + Assert.IsType<MockRegionViewAViewModel>(page.ContentRegion.Content.BindingContext); |
| 288 | + } |
254 | 289 | } |
0 commit comments