Skip to content

Commit d8751ab

Browse files
committed
Change the test setup instead changing the NavigationManager.
1 parent 3ed2b74 commit d8751ab

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/Components/Components/src/NavigationManager.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,6 @@ public event EventHandler<EventArgs> NotFoundEvent
6262
private string? _uri;
6363
private bool _isInitialized;
6464

65-
/// <summary>
66-
/// Gets a value indicating whether the <see cref="NavigationManager"/> has been initialized.
67-
/// </summary>
68-
/// <remarks>
69-
/// The <see cref="NavigationManager"/> must be initialized before it can be used to navigate or handle navigation events.
70-
/// Initialization typically involves setting the base URI and the current URI.
71-
/// </remarks>
72-
public bool IsInitialized => _isInitialized;
73-
7465
/// <summary>
7566
/// Gets or sets the current base URI. The <see cref="BaseUri" /> is always represented as an absolute URI in string form with trailing slash.
7667
/// Typically this corresponds to the 'href' attribute on the document's &lt;base&gt; element.

src/Components/Components/src/PublicAPI.Unshipped.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#nullable enable
22
Microsoft.AspNetCore.Components.NavigationManager.NotFoundEvent -> System.EventHandler<System.EventArgs!>!
33
virtual Microsoft.AspNetCore.Components.NavigationManager.NotFound() -> void
4-
Microsoft.AspNetCore.Components.NavigationManager.IsInitialized.get -> bool
54
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.ComponentStatePersistenceManager(Microsoft.Extensions.Logging.ILogger<Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager!>! logger, System.IServiceProvider! serviceProvider) -> void
65
Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.SetPlatformRenderMode(Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
76
Microsoft.AspNetCore.Components.Infrastructure.RegisterPersistentComponentStateServiceCollectionExtensions

src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal async Task InitializeStandardComponentServicesAsync(
8181
var navigationManager = httpContext.RequestServices.GetRequiredService<NavigationManager>();
8282
((IHostEnvironmentNavigationManager)navigationManager)?.Initialize(GetContextBaseUri(httpContext.Request), GetFullUri(httpContext.Request));
8383

84-
if (navigationManager != null && navigationManager.IsInitialized)
84+
if (navigationManager != null)
8585
{
8686
navigationManager.NotFoundEvent += SetNotFoundResponse;
8787
}

src/Mvc/Mvc.TagHelpers/test/ComponentTagHelperTest.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ private static TagHelperOutput GetTagHelperOutput()
7777

7878
private ViewContext GetViewContext()
7979
{
80-
var navManager = new Mock<NavigationManager>();
81-
navManager.As<IHostEnvironmentNavigationManager>();
82-
8380
var httpContext = new DefaultHttpContext
8481
{
8582
RequestServices = new ServiceCollection()
@@ -89,7 +86,7 @@ private ViewContext GetViewContext()
8986
x => x.CreateProtector(It.IsAny<string>()) == Mock.Of<IDataProtector>()))
9087
.AddLogging()
9188
.AddScoped<ComponentStatePersistenceManager>()
92-
.AddScoped(_ => navManager.Object)
89+
.AddScoped<NavigationManager, MockNavigationManager>()
9390
.AddScoped<HttpContextFormDataProvider>()
9491
.BuildServiceProvider(),
9592
};
@@ -104,4 +101,16 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
104101
builder.AddContent(0, "Hello from the component");
105102
}
106103
}
104+
105+
class MockNavigationManager : NavigationManager, IHostEnvironmentNavigationManager
106+
{
107+
public MockNavigationManager()
108+
{
109+
Initialize("https://localhost:85/subdir/", "https://localhost:85/subdir/path?query=value#hash");
110+
}
111+
112+
void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri)
113+
{
114+
}
115+
}
107116
}

0 commit comments

Comments
 (0)