Skip to content

Commit 69c6204

Browse files
Copilotilonatommy
andcommitted
Revert all changes to NavigationManagerTest.cs as requested
Co-authored-by: ilonatommy <[email protected]>
1 parent 3702281 commit 69c6204

File tree

1 file changed

+1
-95
lines changed

1 file changed

+1
-95
lines changed

src/Components/Components/test/NavigationManagerTest.cs

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -886,42 +886,7 @@ public void OnNotFoundSubscriptionIsTriggeredWhenNotFoundCalled()
886886
// Assert
887887
Assert.True(notFoundTriggered, "The OnNotFound event was not triggered as expected.");
888888
}
889-
890-
[Fact]
891-
public async Task OnNavigateToCallback_WhenThrows_ShouldBeHandledGracefully()
892-
{
893-
#nullable enable
894-
// Arrange
895-
var baseUri = "scheme://host/";
896-
var uri = "scheme://host/test";
897-
var testNavManager = new TestNavigationManagerWithExceptionHandling(baseUri);
898-
var expectedException = new InvalidOperationException("Test exception from OnNavigateTo");
899-
var exceptionHandledTcs = new TaskCompletionSource();
900-
901-
// First test: Initialize with a callback that throws exceptions
902-
testNavManager.Initialize(baseUri, uri, uri => testNavManager.GetErrorHandledTask(ThrowingMethod(uri), exceptionHandledTcs));
903-
904-
// Act & Assert
905-
// Verify that the wrapped callback handles the exception gracefully
906-
var wrappedException = testNavManager.TriggerOnNavigateToCallback(uri);
907-
908-
// Should be null because the exception was handled gracefully
909-
Assert.Null(wrappedException);
910-
911-
await exceptionHandledTcs.Task;
912-
913-
// Verify that the exception was logged
914-
Assert.Single(testNavManager.HandledExceptions);
915-
Assert.Same(expectedException, testNavManager.HandledExceptions[0]);
916-
917-
async Task ThrowingMethod(string param)
918-
{
919-
await Task.Yield();
920-
throw expectedException;
921-
}
922-
#nullable restore
923-
}
924-
889+
925890
private class TestNavigationManager : NavigationManager
926891
{
927892
public TestNavigationManager()
@@ -967,63 +932,4 @@ protected override void HandleLocationChangingHandlerException(Exception ex, Loc
967932
_exceptionsThrownFromLocationChangingHandlers.Add(ex);
968933
}
969934
}
970-
971-
private class TestNavigationManagerWithExceptionHandling : TestNavigationManager, IHostEnvironmentNavigationManager
972-
{
973-
private Func<string, Task> _onNavigateToCallback;
974-
975-
public List<Exception> HandledExceptions { get; } = new();
976-
977-
public TestNavigationManagerWithExceptionHandling(string baseUri = null, string uri = null)
978-
: base(baseUri, uri)
979-
{
980-
}
981-
982-
public void Initialize(string baseUri, string uri, Func<string, Task> onNavigateTo)
983-
{
984-
_onNavigateToCallback = onNavigateTo;
985-
}
986-
987-
#nullable enable
988-
public Exception? TriggerOnNavigateToCallback(string uri)
989-
#nullable restore
990-
{
991-
try
992-
{
993-
// Simulate the fire-and-forget pattern of RemoteNavigationManager
994-
_ = _onNavigateToCallback(uri);
995-
return null;
996-
}
997-
catch (Exception ex)
998-
{
999-
return ex;
1000-
}
1001-
}
1002-
1003-
protected override void NavigateToCore(string uri, bool forceLoad)
1004-
{
1005-
// Simulate the behavior where NavigateToCore calls the onNavigateTo callback
1006-
// in a fire-and-forget manner when JSRuntime is not available
1007-
if (_onNavigateToCallback is not null)
1008-
{
1009-
_ = _onNavigateToCallback(uri);
1010-
}
1011-
}
1012-
1013-
public async Task GetErrorHandledTask(Task taskToHandle, TaskCompletionSource completionSource = null)
1014-
{
1015-
try
1016-
{
1017-
await taskToHandle;
1018-
}
1019-
catch (Exception ex)
1020-
{
1021-
HandledExceptions.Add(ex);
1022-
}
1023-
finally
1024-
{
1025-
completionSource?.SetResult();
1026-
}
1027-
}
1028-
}
1029935
}

0 commit comments

Comments
 (0)