Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions src/Components/Components/src/Routing/Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task SetParametersAsync(ParameterView parameters)
#pragma warning disable CS0618 // Type or member is obsolete
if (NotFound != null)
{
Log.BothNotFoundParametersSet(_logger);
throw new InvalidOperationException("Both NotFound and NotFoundPage parameters are set on Router component. NotFoundPage is preferred and NotFound will be deprecated. Consider using only NotFoundPage.");
}
#pragma warning restore CS0618 // Type or member is obsolete
if (!typeof(IComponent).IsAssignableFrom(NotFoundPage))
Expand Down Expand Up @@ -451,8 +451,5 @@ private static partial class Log
[LoggerMessage(4, LogLevel.Debug, $"Displaying {nameof(NotFound)} on request", EventName = "DisplayingNotFoundOnRequest")]
internal static partial void DisplayingNotFound(ILogger logger);
#pragma warning restore CS0618 // Type or member is obsolete

[LoggerMessage(5, LogLevel.Warning, "Both NotFound and NotFoundPage parameters are set on Router component. NotFoundPage is preferred and NotFound will be deprecated. Consider using only NotFoundPage.", EventName = "BothNotFoundParametersSet")]
internal static partial void BothNotFoundParametersSet(ILogger logger);
}
}
19 changes: 8 additions & 11 deletions src/Components/Components/test/Routing/RouterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,11 @@ await _renderer.Dispatcher.InvokeAsync(() =>
}

[Fact]
public async Task LogsWarningWhenBothNotFoundAndNotFoundPageAreSet()
public async Task ThrowsExceptionWhenBothNotFoundAndNotFoundPageAreSet()
{
// Arrange
var logger = new TestLogger<Router>();
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(new TestLoggerFactory(logger));
services.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance);
services.AddSingleton<NavigationManager>(_navigationManager);
services.AddSingleton<INavigationInterception, TestNavigationInterception>();
services.AddSingleton<IScrollToLocationHash, TestScrollToLocationHash>();
Expand All @@ -293,15 +292,13 @@ public async Task LogsWarningWhenBothNotFoundAndNotFoundPageAreSet()
{ nameof(Router.NotFoundPage), typeof(NotFoundTestComponent) }
};

// Act
await renderer.Dispatcher.InvokeAsync(() =>
router.SetParametersAsync(ParameterView.FromDictionary(parameters)));
// Act & Assert
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
await renderer.Dispatcher.InvokeAsync(() =>
router.SetParametersAsync(ParameterView.FromDictionary(parameters))));

// Assert
var warningLogs = logger.LogEntries.Where(entry => entry.LogLevel == LogLevel.Warning).ToList();
Assert.Single(warningLogs);
Assert.Contains("Both NotFound and NotFoundPage parameters are set on Router component", warningLogs[0].Message);
Assert.Contains("NotFoundPage is preferred and NotFound will be deprecated", warningLogs[0].Message);
Assert.Contains("Both NotFound and NotFoundPage parameters are set on Router component", exception.Message);
Assert.Contains("NotFoundPage is preferred and NotFound will be deprecated", exception.Message);
}

internal class TestNavigationManager : NavigationManager
Expand Down
Loading