Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected virtual IEnumerable<VisualElement> GetCandidatesFromRegion(IRegion reg
{
var registry = region.Container().Resolve<IRegionNavigationRegistry>();
var registration = registry.Registrations.FirstOrDefault(x => x.Type == ViewType.Region && (x.Name == candidateNavigationContract || x.View.Name == candidateNavigationContract || x.View.FullName == candidateNavigationContract));
if (registration is null)
if (registration is not null)
{
RegionNavigationContentLoader.GetCandidatesFromRegionViews(region, registration.View.FullName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Prism.DryIoc.Maui.Tests.Mocks.ViewModels;
using Prism.DryIoc.Maui.Tests.Mocks.ViewModels;
using Prism.DryIoc.Maui.Tests.Mocks.Views;
using Prism.Navigation.Xaml;

Expand Down Expand Up @@ -251,4 +251,39 @@ public async Task Region_IsDestroyed_OnNavigationGoBack()
var result = await navigationService.NavigateAsync("RegionPage");
Assert.True(result.Success);
}

[Fact]
public void Issue3328_WhenNavigatingToUnregisteredView_ShouldFailWithKeyNotFoundException()
{
// Arrange
var mauiApp = CreateBuilder(prism => prism.RegisterTypes(container =>
{
container.RegisterForNavigation<MockContentRegionPage, MockContentRegionPageViewModel>();
container.RegisterForRegionNavigation<MockRegionViewA, MockRegionViewAViewModel>();
}).CreateWindow(nav => nav.NavigateAsync("MockContentRegionPage"))).Build();
var window = GetWindow(mauiApp);

Assert.IsType<MockContentRegionPage>(window.Page);
var page = window.Page as MockContentRegionPage;
Assert.NotNull(page.ContentRegion.Content);
Assert.IsType<MockRegionViewA>(page.ContentRegion.Content);
Assert.IsType<MockRegionViewAViewModel>(page.ContentRegion.Content.BindingContext);

// Act
var regionManager = mauiApp.Services.GetRequiredService<IRegionManager>();
INavigationResult result = null;

regionManager.RequestNavigate("ContentRegion", "UnregisteredRegion", navResult =>
{
result = navResult;
});

// Assert
Assert.False(result.Success);
var ex = Assert.IsType<KeyNotFoundException>(result.Exception);
Assert.Equal("No view with the name 'UnregisteredRegion' has been registered", ex.Message);

Assert.IsType<MockRegionViewA>(page.ContentRegion.Content);
Assert.IsType<MockRegionViewAViewModel>(page.ContentRegion.Content.BindingContext);
}
}
Loading