Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
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
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
Expand Up @@ -59,6 +59,7 @@ public static EndpointBuilder GetBlazorOpaqueRedirectionEndpoint()
};

routeEndpointBuidler.Metadata.Add(new HttpMethodMetadata([HttpMethods.Get]));
routeEndpointBuidler.Metadata.Add(new ComponentFrameworkEndpointMetadata());

return routeEndpointBuidler;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Endpoints/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#nullable enable
Microsoft.AspNetCore.Components.Endpoints.ComponentFrameworkEndpointMetadata
Microsoft.AspNetCore.Components.Endpoints.ComponentFrameworkEndpointMetadata.ComponentFrameworkEndpointMetadata() -> void
Microsoft.AspNetCore.Components.ResourcePreloader
Microsoft.AspNetCore.Components.ResourcePreloader.ResourcePreloader() -> void
Microsoft.Extensions.DependencyInjection.RazorComponentsRazorComponentBuilderExtensions
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this test

Copy link
Contributor Author

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

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);
}
}
48 changes: 48 additions & 0 deletions src/Components/Endpoints/test/Builder/OpaqueRedirectionTest.cs
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
@@ -1,6 +1,7 @@
// 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.Components.Server;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.AspNetCore.Routing;
Expand Down Expand Up @@ -78,12 +79,14 @@ public static ComponentEndpointConventionBuilder MapBlazorHub(
var disconnectEndpoint = endpoints.Map(
(path.EndsWith('/') ? path : path + "/") + "disconnect/",
endpoints.CreateApplicationBuilder().UseMiddleware<CircuitDisconnectMiddleware>().Build())
.WithDisplayName("Blazor disconnect");
.WithDisplayName("Blazor disconnect")
.WithMetadata(new ComponentFrameworkEndpointMetadata());

var jsInitializersEndpoint = endpoints.Map(
(path.EndsWith('/') ? path : path + "/") + "initializers/",
endpoints.CreateApplicationBuilder().UseMiddleware<CircuitJavaScriptInitializationMiddleware>().Build())
.WithDisplayName("Blazor initializers");
.WithDisplayName("Blazor initializers")
.WithMetadata(new ComponentFrameworkEndpointMetadata());

return new ComponentEndpointConventionBuilder(hubEndpoint, disconnectEndpoint, jsInitializersEndpoint);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs#L142

src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList<object>' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList<object>' could be found (are you missing a using directive or an assembly reference?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are errors here src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList' could be found (are you missing a using directive or an assembly reference?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the compilation error by using OfType<ComponentFrameworkEndpointMetadata>().Any() instead of GetMetadata<ComponentFrameworkEndpointMetadata>() on IList<object>. Commit: 1c1c0b9

{
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>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Components.Endpoints.Infrastructure;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -41,7 +42,8 @@ public override IEnumerable<RouteEndpointBuilder> GetEndpointBuilders(IComponent
context.SetEndpoint(null);

return app(context);
});
})
.WithMetadata(new ComponentFrameworkEndpointMetadata());

return endpointRouteBuilder.GetEndpoints();
}
Expand Down Expand Up @@ -75,6 +77,22 @@ internal IEnumerable<RouteEndpointBuilder> GetEndpoints()
builder.Metadata.Add(metadata);
}

// Add framework endpoint metadata if not already present
var hasFrameworkMetadata = false;
for (var i = 0; i < builder.Metadata.Count; i++)
{
if (builder.Metadata[i] is ComponentFrameworkEndpointMetadata)
{
hasFrameworkMetadata = true;
break;
}
}

if (!hasFrameworkMetadata)
{
builder.Metadata.Add(new ComponentFrameworkEndpointMetadata());
}

yield return builder;
}
}
Expand Down
Loading