From 2b51b4af6d6c4580d92b12da5c8590d0e90dfa03 Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:26:14 +0530 Subject: [PATCH 1/4] Fix the null reference exception for empty shell --- src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs b/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs index eb6f4284e626..5bf6ab47fa0d 100644 --- a/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs @@ -193,6 +193,12 @@ public override bool Equals(object obj) => internal void SwitchShellItem(ShellItem newItem, bool animate = true) { + if (newItem is null) + throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?"); + + if (newItem.CurrentItem is null) + throw new InvalidOperationException($"Content not found for active {newItem}. Title: {newItem.Title}. Route: {newItem.Route}."); + var navItems = FlyoutItems.OfType(); // Implicit items aren't items that are surfaced to the user From 048eecf8ef4fb3fe96447e20b957571ac53f6df2 Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Tue, 8 Apr 2025 16:28:34 +0530 Subject: [PATCH 2/4] Committed the test cases --- .../Elements/Shell/ShellTests.Android.cs | 16 ++++++++++++++++ .../Elements/Shell/ShellTests.Windows.cs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs index a97d45bfe8dd..b130601942ef 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs @@ -634,5 +634,21 @@ async Task TapToSelect(ContentPage page) pagerParent.CurrentItem = shellSection.Items.IndexOf(shellContent); await OnNavigatedToAsync(page); } + + [Fact(DisplayName = "Initialize Empty Shell Throws InvalidOperationException")] + public async Task InitializeEmptyShellThrowsInvalidOperationException() + { + SetupBuilder(); + + var shell = new Shell(); + + await Assert.ThrowsAsync(async () => + { + await CreateHandlerAndAddToWindow(shell, (handler) => + { + return Task.CompletedTask; + }); + }); + } } } diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs index b1932396b75a..505b9deec3c9 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs @@ -819,5 +819,21 @@ AnimatedIcon GetNativeAnimatedIcon(ShellHandler shellHandler) return animatedIcon; } + + [Fact(DisplayName = "Initialize Empty Shell Throws InvalidOperationException")] + public async Task InitializeEmptyShellThrowsInvalidOperationException() + { + SetupBuilder(); + + var shell = new Shell(); + + await Assert.ThrowsAsync(async () => + { + await CreateHandlerAndAddToWindow(shell, (handler) => + { + return Task.CompletedTask; + }); + }); + } } } From d144451b2b98e56b4fa5a4d716ea7bff0bcb0193 Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:57:00 +0530 Subject: [PATCH 3/4] modified the test case --- .../Elements/Shell/ShellTests.Android.cs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs index b130601942ef..bbe0059b7822 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs @@ -634,21 +634,5 @@ async Task TapToSelect(ContentPage page) pagerParent.CurrentItem = shellSection.Items.IndexOf(shellContent); await OnNavigatedToAsync(page); } - - [Fact(DisplayName = "Initialize Empty Shell Throws InvalidOperationException")] - public async Task InitializeEmptyShellThrowsInvalidOperationException() - { - SetupBuilder(); - - var shell = new Shell(); - - await Assert.ThrowsAsync(async () => - { - await CreateHandlerAndAddToWindow(shell, (handler) => - { - return Task.CompletedTask; - }); - }); - } } -} +} \ No newline at end of file From 5e320ea633de4ec90b7aeea4f168b58d60886b2a Mon Sep 17 00:00:00 2001 From: Shalini-Ashokan <102292178+Shalini-Ashokan@users.noreply.github.com> Date: Wed, 9 Apr 2025 10:00:44 +0530 Subject: [PATCH 4/4] removed unwanted changes --- .../tests/DeviceTests/Elements/Shell/ShellTests.Android.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs index bbe0059b7822..a97d45bfe8dd 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Android.cs @@ -635,4 +635,4 @@ async Task TapToSelect(ContentPage page) await OnNavigatedToAsync(page); } } -} \ No newline at end of file +}