diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs index 7e1dbb47c2..06bc6f52eb 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/Infrastructure/PageActionDescriptorProvider.cs @@ -75,6 +75,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure { var descriptor = new PageActionDescriptor { + ActionConstraints = selector.ActionConstraints.ToList(), + AreaName = model.AreaName, AttributeRouteInfo = new AttributeRouteInfo { Name = selector.AttributeRouteModel.Name, @@ -84,11 +86,11 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure SuppressPathMatching = selector.AttributeRouteModel.SuppressPathMatching, }, DisplayName = $"Page: {model.ViewEnginePath}", + EndpointMetadata = selector.EndpointMetadata.ToList(), FilterDescriptors = Array.Empty(), Properties = new Dictionary(model.Properties), RelativePath = model.RelativePath, ViewEnginePath = model.ViewEnginePath, - AreaName = model.AreaName, }; foreach (var kvp in model.RouteValues) diff --git a/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs index 29f7214448..41055bf878 100644 --- a/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.RazorPages/Internal/CompiledPageActionDescriptorBuilder.cs @@ -49,6 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal ActionConstraints = actionDescriptor.ActionConstraints, AttributeRouteInfo = actionDescriptor.AttributeRouteInfo, BoundProperties = boundProperties, + EndpointMetadata = actionDescriptor.EndpointMetadata, FilterDescriptors = filters, HandlerMethods = handlerMethods, HandlerTypeInfo = applicationModel.HandlerType, diff --git a/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Infrastructure/PageActionDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Infrastructure/PageActionDescriptorProviderTest.cs index 095a5f5415..4b1e2c4429 100644 --- a/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Infrastructure/PageActionDescriptorProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Infrastructure/PageActionDescriptorProviderTest.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using Microsoft.AspNetCore.Mvc.Abstractions; +using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.Extensions.Options; using Moq; @@ -167,6 +168,74 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure Assert.Equal("Accounts/Test/{id:int?}", descriptor.AttributeRouteInfo.Template); } + [Fact] + public void GetDescriptors_CopiesActionConstraintsFromModel() + { + // Arrange + var expected = Mock.Of(); + var model = new PageRouteModel("/Areas/Accounts/Pages/Test.cshtml", "/Test", "Accounts") + { + Selectors = + { + new SelectorModel + { + AttributeRouteModel = new AttributeRouteModel(), + ActionConstraints = { expected } + } + }, + }; + var applicationModelProvider = new TestPageRouteModelProvider(model); + var provider = new PageActionDescriptorProvider( + new[] { applicationModelProvider }, + GetAccessor(), + GetRazorPagesOptions()); + var context = new ActionDescriptorProviderContext(); + + // Act + provider.OnProvidersExecuting(context); + + // Assert + var result = Assert.Single(context.Results); + var descriptor = Assert.IsType(result); + Assert.Equal(model.RelativePath, descriptor.RelativePath); + var actual = Assert.Single(descriptor.ActionConstraints); + Assert.Same(expected, actual); + } + + [Fact] + public void GetDescriptors_CopiesEndPointMetadataFromModel() + { + // Arrange + var expected = new object(); + var model = new PageRouteModel("/Test.cshtml", "/Test", "Accounts") + { + Selectors = + { + new SelectorModel + { + AttributeRouteModel = new AttributeRouteModel(), + EndpointMetadata = { expected } + } + }, + }; + var applicationModelProvider = new TestPageRouteModelProvider(model); + var provider = new PageActionDescriptorProvider( + new[] { applicationModelProvider }, + GetAccessor(), + GetRazorPagesOptions()); + var context = new ActionDescriptorProviderContext(); + + // Act + provider.OnProvidersExecuting(context); + + // Assert + var result = Assert.Single(context.Results); + var descriptor = Assert.IsType(result); + Assert.Equal(model.RelativePath, descriptor.RelativePath); + var actual = Assert.Single(descriptor.EndpointMetadata); + Assert.Same(expected, actual); + } + [Fact] public void GetDescriptors_AddsActionDescriptorForEachSelector() { diff --git a/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Internal/CompiledPageActionDescriptorBuilderTest.cs b/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Internal/CompiledPageActionDescriptorBuilderTest.cs index 2d08aee3d8..7d12648d04 100644 --- a/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Internal/CompiledPageActionDescriptorBuilderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.RazorPages.Test/Internal/CompiledPageActionDescriptorBuilderTest.cs @@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal { ActionConstraints = new List(), AttributeRouteInfo = new AttributeRouteInfo(), + EndpointMetadata = new List(), FilterDescriptors = new List(), RelativePath = "/Foo", RouteValues = new Dictionary(), @@ -40,6 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal // Assert Assert.Same(actionDescriptor.ActionConstraints, actual.ActionConstraints); Assert.Same(actionDescriptor.AttributeRouteInfo, actual.AttributeRouteInfo); + Assert.Same(actionDescriptor.EndpointMetadata, actual.EndpointMetadata); Assert.Same(actionDescriptor.RelativePath, actual.RelativePath); Assert.Same(actionDescriptor.RouteValues, actual.RouteValues); Assert.Same(actionDescriptor.ViewEnginePath, actual.ViewEnginePath);