-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add ComponentFrameworkEndpointMetadata and ConfigureFrameworkEndpoints to identify and configure Blazor infrastructure endpoints #63821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.AspNetCore.Components.Endpoints; | ||
|
||
/// <summary> | ||
/// Metadata that identifies infrastructure endpoints for Blazor framework functionality. | ||
/// This marker is used to distinguish framework endpoints (like opaque redirection, | ||
/// disconnect, and JavaScript initializers) from regular component endpoints. | ||
/// </summary> | ||
public sealed class ComponentFrameworkEndpointMetadata | ||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.Endpoints; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Components.Tests.Builder; | ||
|
||
public class ComponentFrameworkEndpointMetadataTest | ||
{ | ||
[Fact] | ||
public void ComponentFrameworkEndpointMetadata_CanBeCreated() | ||
{ | ||
// Arrange & Act | ||
var metadata = new ComponentFrameworkEndpointMetadata(); | ||
|
||
// Assert | ||
Assert.NotNull(metadata); | ||
} | ||
|
||
[Fact] | ||
public void ComponentFrameworkEndpointMetadata_IsSealed() | ||
{ | ||
// Arrange & Act | ||
var type = typeof(ComponentFrameworkEndpointMetadata); | ||
|
||
// Assert | ||
Assert.True(type.IsSealed); | ||
} | ||
|
||
[Fact] | ||
public void ComponentFrameworkEndpointMetadata_HasNoPublicProperties() | ||
{ | ||
// Arrange & Act | ||
var type = typeof(ComponentFrameworkEndpointMetadata); | ||
var properties = type.GetProperties(); | ||
|
||
// Assert | ||
Assert.Empty(properties); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components.Endpoints; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Components.Tests.Builder; | ||
|
||
public class OpaqueRedirectionTest | ||
{ | ||
[Fact] | ||
public void GetBlazorOpaqueRedirectionEndpoint_ContainsComponentFrameworkEndpointMetadata() | ||
{ | ||
// Arrange & Act | ||
var endpointBuilder = OpaqueRedirection.GetBlazorOpaqueRedirectionEndpoint(); | ||
var endpoint = endpointBuilder.Build(); | ||
|
||
// Assert | ||
var metadata = endpoint.Metadata.GetMetadata<ComponentFrameworkEndpointMetadata>(); | ||
Assert.NotNull(metadata); | ||
} | ||
|
||
[Fact] | ||
public void GetBlazorOpaqueRedirectionEndpoint_HasCorrectDisplayName() | ||
{ | ||
// Arrange & Act | ||
var endpointBuilder = OpaqueRedirection.GetBlazorOpaqueRedirectionEndpoint(); | ||
var endpoint = endpointBuilder.Build(); | ||
|
||
// Assert | ||
Assert.Equal("Blazor Opaque Redirection", endpoint.DisplayName); | ||
} | ||
|
||
[Fact] | ||
public void GetBlazorOpaqueRedirectionEndpoint_HasHttpGetMethod() | ||
{ | ||
// Arrange & Act | ||
var endpointBuilder = OpaqueRedirection.GetBlazorOpaqueRedirectionEndpoint(); | ||
var endpoint = endpointBuilder.Build(); | ||
|
||
// Assert | ||
var httpMethodMetadata = endpoint.Metadata.GetMetadata<HttpMethodMetadata>(); | ||
Assert.NotNull(httpMethodMetadata); | ||
Assert.Contains(HttpMethods.Get, httpMethodMetadata.HttpMethods); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
using System.Diagnostics; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Components.Endpoints; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Configuration; | ||
|
@@ -122,6 +123,37 @@ | |
Assert.Equal(new[] { "first-in", "last-in" }, populatedMetadata); | ||
} | ||
|
||
[Fact] | ||
public void MapBlazorHub_AddsComponentFrameworkEndpointMetadata() | ||
{ | ||
// Arrange | ||
var applicationBuilder = CreateAppBuilder(); | ||
var frameworkEndpoints = new List<string>(); | ||
|
||
// Act | ||
var app = applicationBuilder | ||
.UseRouting() | ||
.UseEndpoints(endpoints => | ||
{ | ||
endpoints | ||
.MapBlazorHub() | ||
.Finally(builder => | ||
{ | ||
if (builder.Metadata.GetMetadata<ComponentFrameworkEndpointMetadata>() is not null) | ||
Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs
|
||
|
||
{ | ||
frameworkEndpoints.Add(builder.DisplayName); | ||
} | ||
}); | ||
}).Build(); | ||
|
||
// Trigger endpoint construction | ||
app.Invoke(new DefaultHttpContext()); | ||
|
||
// Assert | ||
Assert.Contains("Blazor disconnect", frameworkEndpoints); | ||
Assert.Contains("Blazor initializers", frameworkEndpoints); | ||
} | ||
|
||
private IApplicationBuilder CreateAppBuilder() | ||
{ | ||
var environment = new Mock<IWebHostEnvironment>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the ComponentFrameworkEndpointMetadataTest.cs file. Commit: 1c1c0b9