Copy action constraints and EndPointMetadata when setting up a PageActionDescriptor (#8208)
* Copy action constraints and EndPointMetadata when setting up a PageActionDescriptor Fixes #8207
This commit is contained in:
parent
ac410b76d9
commit
a375cba359
|
|
@ -75,6 +75,8 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
{
|
{
|
||||||
var descriptor = new PageActionDescriptor
|
var descriptor = new PageActionDescriptor
|
||||||
{
|
{
|
||||||
|
ActionConstraints = selector.ActionConstraints.ToList(),
|
||||||
|
AreaName = model.AreaName,
|
||||||
AttributeRouteInfo = new AttributeRouteInfo
|
AttributeRouteInfo = new AttributeRouteInfo
|
||||||
{
|
{
|
||||||
Name = selector.AttributeRouteModel.Name,
|
Name = selector.AttributeRouteModel.Name,
|
||||||
|
|
@ -84,11 +86,11 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
SuppressPathMatching = selector.AttributeRouteModel.SuppressPathMatching,
|
SuppressPathMatching = selector.AttributeRouteModel.SuppressPathMatching,
|
||||||
},
|
},
|
||||||
DisplayName = $"Page: {model.ViewEnginePath}",
|
DisplayName = $"Page: {model.ViewEnginePath}",
|
||||||
|
EndpointMetadata = selector.EndpointMetadata.ToList(),
|
||||||
FilterDescriptors = Array.Empty<FilterDescriptor>(),
|
FilterDescriptors = Array.Empty<FilterDescriptor>(),
|
||||||
Properties = new Dictionary<object, object>(model.Properties),
|
Properties = new Dictionary<object, object>(model.Properties),
|
||||||
RelativePath = model.RelativePath,
|
RelativePath = model.RelativePath,
|
||||||
ViewEnginePath = model.ViewEnginePath,
|
ViewEnginePath = model.ViewEnginePath,
|
||||||
AreaName = model.AreaName,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var kvp in model.RouteValues)
|
foreach (var kvp in model.RouteValues)
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
ActionConstraints = actionDescriptor.ActionConstraints,
|
ActionConstraints = actionDescriptor.ActionConstraints,
|
||||||
AttributeRouteInfo = actionDescriptor.AttributeRouteInfo,
|
AttributeRouteInfo = actionDescriptor.AttributeRouteInfo,
|
||||||
BoundProperties = boundProperties,
|
BoundProperties = boundProperties,
|
||||||
|
EndpointMetadata = actionDescriptor.EndpointMetadata,
|
||||||
FilterDescriptors = filters,
|
FilterDescriptors = filters,
|
||||||
HandlerMethods = handlerMethods,
|
HandlerMethods = handlerMethods,
|
||||||
HandlerTypeInfo = applicationModel.HandlerType,
|
HandlerTypeInfo = applicationModel.HandlerType,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -167,6 +168,74 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure
|
||||||
Assert.Equal("Accounts/Test/{id:int?}", descriptor.AttributeRouteInfo.Template);
|
Assert.Equal("Accounts/Test/{id:int?}", descriptor.AttributeRouteInfo.Template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDescriptors_CopiesActionConstraintsFromModel()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = Mock.Of<IActionConstraint>();
|
||||||
|
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<MvcOptions>(),
|
||||||
|
GetRazorPagesOptions());
|
||||||
|
var context = new ActionDescriptorProviderContext();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
provider.OnProvidersExecuting(context);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var result = Assert.Single(context.Results);
|
||||||
|
var descriptor = Assert.IsType<PageActionDescriptor>(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<MvcOptions>(),
|
||||||
|
GetRazorPagesOptions());
|
||||||
|
var context = new ActionDescriptorProviderContext();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
provider.OnProvidersExecuting(context);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
var result = Assert.Single(context.Results);
|
||||||
|
var descriptor = Assert.IsType<PageActionDescriptor>(result);
|
||||||
|
Assert.Equal(model.RelativePath, descriptor.RelativePath);
|
||||||
|
var actual = Assert.Single(descriptor.EndpointMetadata);
|
||||||
|
Assert.Same(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void GetDescriptors_AddsActionDescriptorForEachSelector()
|
public void GetDescriptors_AddsActionDescriptorForEachSelector()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
{
|
{
|
||||||
ActionConstraints = new List<IActionConstraintMetadata>(),
|
ActionConstraints = new List<IActionConstraintMetadata>(),
|
||||||
AttributeRouteInfo = new AttributeRouteInfo(),
|
AttributeRouteInfo = new AttributeRouteInfo(),
|
||||||
|
EndpointMetadata = new List<object>(),
|
||||||
FilterDescriptors = new List<FilterDescriptor>(),
|
FilterDescriptors = new List<FilterDescriptor>(),
|
||||||
RelativePath = "/Foo",
|
RelativePath = "/Foo",
|
||||||
RouteValues = new Dictionary<string, string>(),
|
RouteValues = new Dictionary<string, string>(),
|
||||||
|
|
@ -40,6 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages.Internal
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Same(actionDescriptor.ActionConstraints, actual.ActionConstraints);
|
Assert.Same(actionDescriptor.ActionConstraints, actual.ActionConstraints);
|
||||||
Assert.Same(actionDescriptor.AttributeRouteInfo, actual.AttributeRouteInfo);
|
Assert.Same(actionDescriptor.AttributeRouteInfo, actual.AttributeRouteInfo);
|
||||||
|
Assert.Same(actionDescriptor.EndpointMetadata, actual.EndpointMetadata);
|
||||||
Assert.Same(actionDescriptor.RelativePath, actual.RelativePath);
|
Assert.Same(actionDescriptor.RelativePath, actual.RelativePath);
|
||||||
Assert.Same(actionDescriptor.RouteValues, actual.RouteValues);
|
Assert.Same(actionDescriptor.RouteValues, actual.RouteValues);
|
||||||
Assert.Same(actionDescriptor.ViewEnginePath, actual.ViewEnginePath);
|
Assert.Same(actionDescriptor.ViewEnginePath, actual.ViewEnginePath);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue