[Fixes #4506] Move and rename ActionDescriptor.Name to ControllerActionDescriptor.ActionName
This commit is contained in:
parent
5f4ca4fa66
commit
6a6d2e0d9f
|
|
@ -24,8 +24,6 @@ namespace Microsoft.AspNetCore.Mvc.Abstractions
|
|||
/// </summary>
|
||||
public string Id { get; }
|
||||
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of route values that must be provided by routing
|
||||
/// for the action to be selected.
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Mvc.Controllers
|
|||
{
|
||||
public string ControllerName { get; set; }
|
||||
|
||||
public virtual string ActionName { get; set; }
|
||||
|
||||
public MethodInfo MethodInfo { get; set; }
|
||||
|
||||
public TypeInfo ControllerTypeInfo { get; set; }
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
|
||||
var actionDescriptor = new ControllerActionDescriptor()
|
||||
{
|
||||
Name = action.ActionName,
|
||||
ActionName = action.ActionName,
|
||||
MethodInfo = action.ActionMethod,
|
||||
Parameters = parameterDescriptors,
|
||||
AttributeRouteInfo = CreateAttributeRouteInfo(actionAttributeRoute, controllerAttributeRoute)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
|||
/// <para>
|
||||
/// The typical scheme for action selection in an MVC application is that an action will require the
|
||||
/// matching values for its <see cref="ControllerActionDescriptor.ControllerName"/> and
|
||||
/// <see cref="ActionDescriptor.Name"/>
|
||||
/// <see cref="ControllerActionDescriptor.ActionName"/>
|
||||
/// </para>
|
||||
/// <example>
|
||||
/// For an action like <code>MyApp.Controllers.HomeController.Index()</code>, in order to be selected, the
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
|
|
@ -19,6 +20,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
/// </summary>
|
||||
public class PartialViewResultExecutor : ViewExecutor
|
||||
{
|
||||
private const string ActionNameKey = "action";
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="PartialViewResultExecutor"/>.
|
||||
/// </summary>
|
||||
|
|
@ -69,7 +72,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
}
|
||||
|
||||
var viewEngine = viewResult.ViewEngine ?? ViewEngine;
|
||||
var viewName = viewResult.ViewName ?? actionContext.ActionDescriptor.Name;
|
||||
var viewName = viewResult.ViewName ?? GetActionName(actionContext);
|
||||
|
||||
var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: false);
|
||||
var originalResult = result;
|
||||
|
|
@ -157,5 +160,47 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
viewResult.ContentType,
|
||||
viewResult.StatusCode);
|
||||
}
|
||||
|
||||
private static string GetActionName(ActionContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
object routeValue;
|
||||
if (!context.RouteData.Values.TryGetValue(ActionNameKey, out routeValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var actionDescriptor = context.ActionDescriptor;
|
||||
string normalizedValue = null;
|
||||
if (actionDescriptor.AttributeRouteInfo != null)
|
||||
{
|
||||
object match;
|
||||
if (actionDescriptor.RouteValueDefaults.TryGetValue(ActionNameKey, out match))
|
||||
{
|
||||
normalizedValue = match?.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string value;
|
||||
if (actionDescriptor.RouteValues.TryGetValue(ActionNameKey, out value) &&
|
||||
!string.IsNullOrEmpty(value))
|
||||
{
|
||||
normalizedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
var stringRouteValue = routeValue?.ToString();
|
||||
if (string.Equals(normalizedValue, stringRouteValue, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return normalizedValue;
|
||||
}
|
||||
|
||||
return stringRouteValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
|
|
@ -19,6 +20,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
/// </summary>
|
||||
public class ViewResultExecutor : ViewExecutor
|
||||
{
|
||||
private const string ActionNameKey = "action";
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ViewResultExecutor"/>.
|
||||
/// </summary>
|
||||
|
|
@ -69,7 +72,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
}
|
||||
|
||||
var viewEngine = viewResult.ViewEngine ?? ViewEngine;
|
||||
var viewName = viewResult.ViewName ?? actionContext.ActionDescriptor.Name;
|
||||
|
||||
var viewName = viewResult.ViewName ?? GetActionName(actionContext);
|
||||
|
||||
var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
|
||||
var originalResult = result;
|
||||
|
|
@ -170,5 +174,47 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
viewResult.ContentType,
|
||||
viewResult.StatusCode);
|
||||
}
|
||||
|
||||
private static string GetActionName(ActionContext context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
object routeValue;
|
||||
if (!context.RouteData.Values.TryGetValue(ActionNameKey, out routeValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var actionDescriptor = context.ActionDescriptor;
|
||||
string normalizedValue = null;
|
||||
if (actionDescriptor.AttributeRouteInfo != null)
|
||||
{
|
||||
object match;
|
||||
if (actionDescriptor.RouteValueDefaults.TryGetValue(ActionNameKey, out match))
|
||||
{
|
||||
normalizedValue = match?.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string value;
|
||||
if (actionDescriptor.RouteValues.TryGetValue(ActionNameKey, out value) &&
|
||||
!string.IsNullOrEmpty(value))
|
||||
{
|
||||
normalizedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
var stringRouteValue = routeValue?.ToString();
|
||||
if (string.Equals(normalizedValue, stringRouteValue, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return normalizedValue;
|
||||
}
|
||||
|
||||
return stringRouteValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
|
|
@ -24,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// Gets or sets the name of the partial view to render.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When <c>null</c>, defaults to <see cref="Abstractions.ActionDescriptor.Name"/>.
|
||||
/// When <c>null</c>, defaults to <see cref="ControllerActionDescriptor.ActionName"/>.
|
||||
/// </remarks>
|
||||
public string ViewName { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
|
|
@ -24,7 +25,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// Gets or sets the name of the view to render.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// When <c>null</c>, defaults to <see cref="Abstractions.ActionDescriptor.Name"/>.
|
||||
/// When <c>null</c>, defaults to <see cref="ControllerActionDescriptor.ActionName"/>.
|
||||
/// </remarks>
|
||||
public string ViewName { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
var result = InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Patch", result.Name);
|
||||
Assert.Equal("Patch", result.ActionName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -419,7 +419,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
var result = InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Put", result.Name);
|
||||
Assert.Equal("Put", result.ActionName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -451,7 +451,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
// Act
|
||||
var result = actionDescriptorProvider
|
||||
.GetDescriptors()
|
||||
.FirstOrDefault(x => x.ControllerName == "NonAction" && x.Name == actionName);
|
||||
.FirstOrDefault(x => x.ControllerName == "NonAction" && x.ActionName == actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
|
|
@ -504,10 +504,10 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
var result = InvokeActionSelector(routeContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(actionName, result.Name);
|
||||
Assert.Equal(actionName, result.ActionName);
|
||||
}
|
||||
|
||||
private ActionDescriptor InvokeActionSelector(RouteContext context)
|
||||
private ControllerActionDescriptor InvokeActionSelector(RouteContext context)
|
||||
{
|
||||
var actionDescriptorProvider = GetActionDescriptorProvider();
|
||||
|
||||
|
|
@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
GetActionConstraintCache(actionConstraintProviders),
|
||||
NullLoggerFactory.Instance);
|
||||
|
||||
return defaultActionSelector.Select(context);
|
||||
return (ControllerActionDescriptor)defaultActionSelector.Select(context);
|
||||
}
|
||||
|
||||
private ControllerActionDescriptorProvider GetActionDescriptorProvider()
|
||||
|
|
@ -664,9 +664,9 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
|
||||
private static ActionDescriptor CreateAction(string area, string controller, string action)
|
||||
{
|
||||
var actionDescriptor = new ActionDescriptor()
|
||||
var actionDescriptor = new ControllerActionDescriptor()
|
||||
{
|
||||
Name = string.Format("Area: {0}, Controller: {1}, Action: {2}", area, controller, action),
|
||||
ActionName = string.Format("Area: {0}, Controller: {1}, Action: {2}", area, controller, action),
|
||||
Parameters = new List<ParameterDescriptor>(),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
|
||||
// Act
|
||||
var descriptors = provider.GetDescriptors();
|
||||
var actionNames = descriptors.Select(ad => ad.Name);
|
||||
var actionNames = descriptors.Select(ad => ad.ActionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(new[] { "GetPerson", "ShowPeople", }, actionNames);
|
||||
|
|
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
|
||||
// Act
|
||||
var descriptors = provider.GetDescriptors();
|
||||
var descriptor = descriptors.Single(ad => ad.Name == nameof(PersonController.GetPerson));
|
||||
var descriptor = descriptors.Single(ad => ad.ActionName == nameof(PersonController.GetPerson));
|
||||
|
||||
// Assert
|
||||
Assert.Equal($"{controllerTypeInfo.FullName}.{nameof(PersonController.GetPerson)} ({controllerTypeInfo.Assembly.GetName().Name})", descriptor.DisplayName);
|
||||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptor = Assert.Single(descriptors);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("OnlyPost", descriptor.Name);
|
||||
Assert.Equal("OnlyPost", descriptor.ActionName);
|
||||
|
||||
var constraint = Assert.IsType<HttpMethodActionConstraint>(Assert.Single(descriptor.ActionConstraints));
|
||||
Assert.Equal(new string[] { "POST" }, constraint.HttpMethods);
|
||||
|
|
@ -123,8 +123,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
typeof(ActionParametersController).GetTypeInfo());
|
||||
|
||||
// Assert
|
||||
var main = Assert.Single(descriptors,
|
||||
d => d.Name.Equals(nameof(ActionParametersController.RequiredInt)));
|
||||
var main = Assert.Single(descriptors.Cast<ControllerActionDescriptor>(),
|
||||
d => d.ActionName.Equals(nameof(ActionParametersController.RequiredInt)));
|
||||
|
||||
Assert.NotNull(main.Parameters);
|
||||
var id = Assert.Single(main.Parameters);
|
||||
|
|
@ -142,8 +142,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
typeof(ActionParametersController).GetTypeInfo());
|
||||
|
||||
// Assert
|
||||
var main = Assert.Single(descriptors,
|
||||
d => d.Name.Equals(nameof(ActionParametersController.MultipleParameters)));
|
||||
var main = Assert.Single(descriptors.Cast<ControllerActionDescriptor>(),
|
||||
d => d.ActionName.Equals(nameof(ActionParametersController.MultipleParameters)));
|
||||
|
||||
Assert.NotNull(main.Parameters);
|
||||
var id = Assert.Single(main.Parameters, p => p.Name == "id");
|
||||
|
|
@ -167,8 +167,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
typeof(ActionParametersController).GetTypeInfo());
|
||||
|
||||
// Assert
|
||||
var main = Assert.Single(descriptors,
|
||||
d => d.Name.Equals(nameof(ActionParametersController.DifferentCasing)));
|
||||
var main = Assert.Single(descriptors.Cast<ControllerActionDescriptor>(),
|
||||
d => d.ActionName.Equals(nameof(ActionParametersController.DifferentCasing)));
|
||||
|
||||
Assert.NotNull(main.Parameters);
|
||||
var id = Assert.Single(main.Parameters, p => p.Name == "id");
|
||||
|
|
@ -200,8 +200,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
typeof(ActionParametersController).GetTypeInfo());
|
||||
|
||||
// Assert
|
||||
var fromBody = Assert.Single(descriptors,
|
||||
d => d.Name.Equals(actionName));
|
||||
var fromBody = Assert.Single(descriptors.Cast<ControllerActionDescriptor>(),
|
||||
d => d.ActionName.Equals(actionName));
|
||||
|
||||
Assert.NotNull(fromBody.Parameters);
|
||||
var entity = Assert.Single(fromBody.Parameters);
|
||||
|
|
@ -221,8 +221,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
typeof(ActionParametersController).GetTypeInfo());
|
||||
|
||||
// Assert
|
||||
var notFromBody = Assert.Single(descriptors,
|
||||
d => d.Name.Equals(actionName));
|
||||
var notFromBody = Assert.Single(descriptors.Cast<ControllerActionDescriptor>(),
|
||||
d => d.ActionName.Equals(actionName));
|
||||
|
||||
Assert.NotNull(notFromBody.Parameters);
|
||||
var entity = Assert.Single(notFromBody.Parameters);
|
||||
|
|
@ -470,12 +470,12 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptors = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var actions = descriptors.Where(d => d.Name == "MultipleHttpGet");
|
||||
var actions = descriptors.Where(d => d.ActionName == "MultipleHttpGet");
|
||||
Assert.Equal(4, actions.Count());
|
||||
|
||||
foreach (var action in actions)
|
||||
{
|
||||
Assert.Equal("MultipleHttpGet", action.Name);
|
||||
Assert.Equal("MultipleHttpGet", action.ActionName);
|
||||
Assert.Equal("MultiRouteAttributes", action.ControllerName);
|
||||
}
|
||||
|
||||
|
|
@ -495,7 +495,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptors = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var actions = descriptors.Where(d => d.Name == nameof(MultiRouteAttributesController.AcceptVerbs));
|
||||
var actions = descriptors.Where(d => d.ActionName == nameof(MultiRouteAttributesController.AcceptVerbs));
|
||||
Assert.Equal(2, actions.Count());
|
||||
|
||||
foreach (var action in actions)
|
||||
|
|
@ -523,7 +523,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptors = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var action = Assert.Single(descriptors, d => d.Name == "AcceptVerbsOverride");
|
||||
var action = Assert.Single(descriptors, d => d.ActionName == "AcceptVerbsOverride");
|
||||
|
||||
Assert.Equal("MultiRouteAttributes", action.ControllerName);
|
||||
|
||||
|
|
@ -547,7 +547,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptors = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var actions = descriptors.Where(d => d.Name == "AcceptVerbsRouteAttributeAndHttpPut");
|
||||
var actions = descriptors.Where(d => d.ActionName == "AcceptVerbsRouteAttributeAndHttpPut");
|
||||
Assert.Equal(4, actions.Count());
|
||||
|
||||
foreach (var action in actions)
|
||||
|
|
@ -586,7 +586,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptors = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var actions = descriptors.Where(d => d.Name == "AcceptVerbsRouteAttributeWithTemplateAndHttpPut");
|
||||
var actions = descriptors.Where(d => d.ActionName == "AcceptVerbsRouteAttributeWithTemplateAndHttpPut");
|
||||
Assert.Equal(6, actions.Count());
|
||||
|
||||
foreach (var action in actions)
|
||||
|
|
@ -633,10 +633,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var actions = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var controllerAndAction = Assert.Single(actions, a => a.Name.Equals(firstActionName));
|
||||
var controllerAndAction = Assert.Single(actions, a => a.ActionName.Equals(firstActionName));
|
||||
Assert.NotNull(controllerAndAction.AttributeRouteInfo);
|
||||
|
||||
var controllerActionAndOverride = Assert.Single(actions, a => a.Name.Equals(secondActionName));
|
||||
var controllerActionAndOverride = Assert.Single(actions, a => a.ActionName.Equals(secondActionName));
|
||||
Assert.NotNull(controllerActionAndOverride.AttributeRouteInfo);
|
||||
|
||||
Assert.Equal(
|
||||
|
|
@ -656,7 +656,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var descriptors = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var actions = descriptors.Where(d => d.Name.Equals(actionName));
|
||||
var actions = descriptors.Where(d => d.ActionName.Equals(actionName));
|
||||
Assert.Equal(5, actions.Count());
|
||||
|
||||
foreach (var method in new[] { "GET", "POST", "PUT", "PATCH", "DELETE" })
|
||||
|
|
@ -759,7 +759,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
// Assert
|
||||
var action = Assert.Single(actions);
|
||||
|
||||
Assert.Equal("Action", action.Name);
|
||||
Assert.Equal("Action", action.ActionName);
|
||||
Assert.Equal("OnlyRoute", action.ControllerName);
|
||||
|
||||
Assert.NotNull(action.AttributeRouteInfo);
|
||||
|
|
@ -842,7 +842,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var actions = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var getActions = actions.Where(a => a.Name.Equals(getActionName));
|
||||
var getActions = actions.Where(a => a.ActionName.Equals(getActionName));
|
||||
Assert.Equal(2, getActions.Count());
|
||||
|
||||
foreach (var getAction in getActions)
|
||||
|
|
@ -852,7 +852,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
Assert.Equal("Products_Get", getAction.AttributeRouteInfo.Name, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
var editAction = Assert.Single(actions, a => a.Name.Equals(editActionName));
|
||||
var editAction = Assert.Single(actions, a => a.ActionName.Equals(editActionName));
|
||||
Assert.NotNull(editAction.AttributeRouteInfo);
|
||||
Assert.Equal("Products/Edit", editAction.AttributeRouteInfo.Template, StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Equal("Products_Edit", editAction.AttributeRouteInfo.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -870,7 +870,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var actions = provider.GetDescriptors();
|
||||
|
||||
// Assert
|
||||
var getActions = actions.Where(a => a.Name.Equals(getActionName));
|
||||
var getActions = actions.Where(a => a.ActionName.Equals(getActionName));
|
||||
Assert.Equal(2, getActions.Count());
|
||||
|
||||
foreach (var getAction in getActions)
|
||||
|
|
@ -884,7 +884,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
getAction.AttributeRouteInfo.Name, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
var editAction = Assert.Single(actions, a => a.Name.Equals(editActionName));
|
||||
var editAction = Assert.Single(actions, a => a.ActionName.Equals(editActionName));
|
||||
Assert.NotNull(editAction.AttributeRouteInfo);
|
||||
Assert.Equal(
|
||||
"ControllerActionRouteNameTemplates/Edit",
|
||||
|
|
@ -955,7 +955,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
Assert.NotNull(actionDescriptors);
|
||||
Assert.Equal(4, actionDescriptors.Count());
|
||||
|
||||
var indexAction = Assert.Single(actionDescriptors, ad => ad.Name.Equals("Index"));
|
||||
var indexAction = Assert.Single(actionDescriptors, ad => ad.ActionName.Equals("Index"));
|
||||
|
||||
Assert.Equal(1, indexAction.RouteValues.Count);
|
||||
|
||||
|
|
@ -1058,10 +1058,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
// Assert
|
||||
Assert.Equal(2, actions.Count());
|
||||
|
||||
var action = Assert.Single(actions, a => a.Name == "Edit");
|
||||
var action = Assert.Single(actions, a => a.ActionName == "Edit");
|
||||
Assert.NotNull(action.GetProperty<ApiDescriptionActionData>());
|
||||
|
||||
action = Assert.Single(actions, a => a.Name == "Create");
|
||||
action = Assert.Single(actions, a => a.ActionName == "Create");
|
||||
Assert.Null(action.GetProperty<ApiDescriptionActionData>());
|
||||
}
|
||||
|
||||
|
|
@ -1138,10 +1138,10 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
// Assert
|
||||
Assert.Equal(2, actions.Count());
|
||||
|
||||
var action = Assert.Single(actions, a => a.Name == "Edit");
|
||||
var action = Assert.Single(actions, a => a.ActionName == "Edit");
|
||||
Assert.Equal("Blog", action.GetProperty<ApiDescriptionActionData>().GroupName);
|
||||
|
||||
action = Assert.Single(actions, a => a.Name == "Create");
|
||||
action = Assert.Single(actions, a => a.ActionName == "Create");
|
||||
Assert.Equal("Store", action.GetProperty<ApiDescriptionActionData>().GroupName);
|
||||
}
|
||||
|
||||
|
|
@ -1331,7 +1331,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var provider = GetProvider(typeof(MultipleRouteProviderOnActionAndControllerController).GetTypeInfo());
|
||||
|
||||
// Act
|
||||
var actions = provider.GetDescriptors().Where(a => a.Name == actionName);
|
||||
var actions = provider.GetDescriptors().Where(a => a.ActionName == actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, actions.Count());
|
||||
|
|
@ -1358,7 +1358,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var provider = GetProvider(typeof(MultipleRouteProviderOnActionAndControllerController).GetTypeInfo());
|
||||
|
||||
// Act
|
||||
var actions = provider.GetDescriptors().Where(a => a.Name == actionName);
|
||||
var actions = provider.GetDescriptors().Where(a => a.ActionName == actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(4, actions.Count());
|
||||
|
|
@ -1397,7 +1397,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
var provider = GetProvider(typeof(MultipleRouteProviderOnActionAndControllerController).GetTypeInfo());
|
||||
|
||||
// Act
|
||||
var actions = provider.GetDescriptors().Where(a => a.Name == actionName);
|
||||
var actions = provider.GetDescriptors().Where(a => a.ActionName == actionName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1, actions.Count());
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
|
@ -184,9 +185,9 @@ namespace Microsoft.AspNetCore.Mvc.Routing
|
|||
|
||||
private static ActionDescriptor CreateActionDescriptor(string area, string controller, string action)
|
||||
{
|
||||
var actionDescriptor = new ActionDescriptor()
|
||||
var actionDescriptor = new ControllerActionDescriptor()
|
||||
{
|
||||
Name = string.Format("Area: {0}, Controller: {1}, Action: {2}", area, controller, action),
|
||||
ActionName = string.Format("Area: {0}, Controller: {1}, Action: {2}", area, controller, action),
|
||||
};
|
||||
|
||||
actionDescriptor.RouteValues.Add("area", area);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
|
|
@ -57,11 +58,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
public void FindView_UsesActionDescriptorName_IfViewNameIsNull()
|
||||
{
|
||||
// Arrange
|
||||
var context = GetActionContext();
|
||||
var executor = GetViewExecutor();
|
||||
|
||||
var viewName = "some-view-name";
|
||||
context.ActionDescriptor.Name = viewName;
|
||||
var context = GetActionContext(viewName);
|
||||
var executor = GetViewExecutor();
|
||||
|
||||
var viewResult = new PartialViewResult
|
||||
{
|
||||
|
|
@ -309,9 +308,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
Assert.Equal(404, context.HttpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
private ActionContext GetActionContext()
|
||||
private ActionContext GetActionContext(string actionName = null)
|
||||
{
|
||||
return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||
var routeData = new RouteData();
|
||||
routeData.Values["action"] = actionName;
|
||||
|
||||
return new ActionContext(new DefaultHttpContext(), routeData, new ControllerActionDescriptor() { ActionName = actionName });
|
||||
}
|
||||
|
||||
private PartialViewResultExecutor GetViewExecutor(DiagnosticSource diagnosticSource = null)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
|
@ -56,11 +57,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
public void FindView_UsesActionDescriptorName_IfViewNameIsNull()
|
||||
{
|
||||
// Arrange
|
||||
var context = GetActionContext();
|
||||
var executor = GetViewExecutor();
|
||||
|
||||
var viewName = "some-view-name";
|
||||
context.ActionDescriptor.Name = viewName;
|
||||
var context = GetActionContext(viewName);
|
||||
var executor = GetViewExecutor();
|
||||
|
||||
var viewResult = new ViewResult
|
||||
{
|
||||
|
|
@ -299,9 +298,12 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
Assert.Equal(404, context.HttpContext.Response.StatusCode);
|
||||
}
|
||||
|
||||
private ActionContext GetActionContext()
|
||||
private ActionContext GetActionContext(string actionName = null)
|
||||
{
|
||||
return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
|
||||
var routeData = new RouteData();
|
||||
routeData.Values["action"] = actionName;
|
||||
|
||||
return new ActionContext(new DefaultHttpContext(), routeData, new ControllerActionDescriptor() { ActionName = actionName });
|
||||
}
|
||||
|
||||
private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticSource = null)
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ namespace System.Web.Http
|
|||
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
||||
var actions = results
|
||||
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||
.Where(ad => ad.Name == "Get")
|
||||
.Where(ad => ad.ActionName == "Get")
|
||||
.ToArray();
|
||||
|
||||
Assert.NotEmpty(actions);
|
||||
|
|
@ -301,7 +301,7 @@ namespace System.Web.Http
|
|||
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
||||
var actions = results
|
||||
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||
.Where(ad => ad.Name == "Put")
|
||||
.Where(ad => ad.ActionName == "Put")
|
||||
.ToArray();
|
||||
|
||||
Assert.NotEmpty(actions);
|
||||
|
|
@ -328,7 +328,7 @@ namespace System.Web.Http
|
|||
var controllerType = typeof(TestControllers.EmployeesController).GetTypeInfo();
|
||||
var actions = results
|
||||
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||
.Where(ad => ad.Name == "Post")
|
||||
.Where(ad => ad.ActionName == "Post")
|
||||
.ToArray();
|
||||
|
||||
Assert.NotEmpty(actions);
|
||||
|
|
@ -357,7 +357,7 @@ namespace System.Web.Http
|
|||
var controllerType = typeof(TestControllers.EventsController).GetTypeInfo();
|
||||
var actions = results
|
||||
.Where(ad => ad.ControllerTypeInfo == controllerType)
|
||||
.Where(ad => ad.Name == name)
|
||||
.Where(ad => ad.ActionName == name)
|
||||
.ToArray();
|
||||
|
||||
Assert.NotEmpty(actions);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace ApplicationModelWebSite
|
|||
[ActionName2("ActionName")]
|
||||
public string GetActionName()
|
||||
{
|
||||
return ControllerContext.ActionDescriptor.Name;
|
||||
return ControllerContext.ActionDescriptor.ActionName;
|
||||
}
|
||||
|
||||
private class ActionName2Attribute : Attribute, IActionModelConvention
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace BasicWebSite
|
||||
|
|
@ -29,7 +30,7 @@ namespace BasicWebSite
|
|||
{
|
||||
if (!context.RouteData.DataTokens.ContainsKey("actionName"))
|
||||
{
|
||||
context.RouteData.DataTokens.Add("actionName", context.ActionDescriptor.Name);
|
||||
context.RouteData.DataTokens.Add("actionName", ((ControllerActionDescriptor)context.ActionDescriptor).ActionName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ namespace FormatterWebSite
|
|||
{
|
||||
var errorInfo = new ErrorInfo
|
||||
{
|
||||
ActionName = context.ActionDescriptor.Name,
|
||||
ActionName = ((ControllerActionDescriptor)context.ActionDescriptor).ActionName,
|
||||
ParameterName = bodyParameter.Name,
|
||||
Errors = parameterBindingErrors.Select(x => x.ErrorMessage).ToList(),
|
||||
Source = "filter"
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace RoutingWebSite
|
|||
routeName = attributeRoutingInfo == null ? null : attributeRoutingInfo.Name,
|
||||
routeValues = new Dictionary<string, object>(_actionContext.RouteData.Values),
|
||||
|
||||
action = _actionContext.ActionDescriptor.Name,
|
||||
action = ((ControllerActionDescriptor) _actionContext.ActionDescriptor).ActionName,
|
||||
controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName,
|
||||
|
||||
link,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace VersioningWebSite
|
|||
routeName = attributeRoutingInfo == null ? null : attributeRoutingInfo.Name,
|
||||
routeValues = new Dictionary<string, object>(_actionContext.RouteData.Values),
|
||||
|
||||
action = _actionContext.ActionDescriptor.Name,
|
||||
action = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ActionName,
|
||||
controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName,
|
||||
|
||||
link,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace WebApiCompatShimWebSite
|
|||
{
|
||||
JsonConvert.SerializeObject(new
|
||||
{
|
||||
ActionName = action.Name,
|
||||
ActionName = action.ActionName,
|
||||
ControllerName = action.ControllerName
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue