From 6a6d2e0d9fce13380c6a868b3eb7fddf8cf274f2 Mon Sep 17 00:00:00 2001 From: jacalvar Date: Thu, 26 May 2016 12:25:54 -0700 Subject: [PATCH] [Fixes #4506] Move and rename ActionDescriptor.Name to ControllerActionDescriptor.ActionName --- .../Abstractions/ActionDescriptor.cs | 2 - .../Controllers/ControllerActionDescriptor.cs | 2 + .../ControllerActionDescriptorBuilder.cs | 2 +- .../Routing/IRouteValueProvider.cs | 2 +- .../Internal/PartialViewResultExecutor.cs | 47 ++++++++++++- .../Internal/ViewResultExecutor.cs | 48 ++++++++++++- .../PartialViewResult.cs | 3 +- .../ViewResult.cs | 3 +- .../DefaultActionSelectorTests.cs | 16 ++--- ...ControllerActionDescriptorProviderTests.cs | 70 +++++++++---------- .../Routing/KnownRouteValueConstraintTests.cs | 5 +- .../Internal/PartialViewResultExecutorTest.cs | 14 ++-- .../Internal/ViewResultExecutorTest.cs | 14 ++-- .../ApiControllerActionDiscoveryTest.cs | 8 +-- .../Controllers/ActionModelController.cs | 2 +- .../Controllers/RoutingController.cs | 3 +- .../ValidateBodyParameterAttribute.cs | 3 +- .../RoutingWebSite/TestResponseGenerator.cs | 2 +- .../TestResponseGenerator.cs | 2 +- .../ActionSelectionFilter.cs | 2 +- 20 files changed, 175 insertions(+), 75 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Abstractions/Abstractions/ActionDescriptor.cs b/src/Microsoft.AspNetCore.Mvc.Abstractions/Abstractions/ActionDescriptor.cs index be416aa30b..64ddd1b849 100644 --- a/src/Microsoft.AspNetCore.Mvc.Abstractions/Abstractions/ActionDescriptor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Abstractions/Abstractions/ActionDescriptor.cs @@ -24,8 +24,6 @@ namespace Microsoft.AspNetCore.Mvc.Abstractions /// public string Id { get; } - public virtual string Name { get; set; } - /// /// Gets or sets the collection of route values that must be provided by routing /// for the action to be selected. diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerActionDescriptor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerActionDescriptor.cs index 7b5ffa5b81..7292139d1a 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerActionDescriptor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Controllers/ControllerActionDescriptor.cs @@ -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; } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs index 9c504aa22c..0d3c8a790d 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/ControllerActionDescriptorBuilder.cs @@ -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) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Routing/IRouteValueProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Routing/IRouteValueProvider.cs index 9917c825f2..b71117f870 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Routing/IRouteValueProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Routing/IRouteValueProvider.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Routing /// /// The typical scheme for action selection in an MVC application is that an action will require the /// matching values for its and - /// + /// /// /// /// For an action like MyApp.Controllers.HomeController.Index(), in order to be selected, the diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs index bef07fccad..a06d1f4e5e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/PartialViewResultExecutor.cs @@ -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 /// public class PartialViewResultExecutor : ViewExecutor { + private const string ActionNameKey = "action"; + /// /// Creates a new . /// @@ -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; + } } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs index 8ca83fe40f..217f97d8c3 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ViewResultExecutor.cs @@ -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 /// public class ViewResultExecutor : ViewExecutor { + private const string ActionNameKey = "action"; + /// /// Creates a new . /// @@ -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; + } } } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs index afa44e1a8b..7abf63632e 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/PartialViewResult.cs @@ -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. /// /// - /// When null, defaults to . + /// When null, defaults to . /// public string ViewName { get; set; } diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs index 14c9e1410a..bc43a62247 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs @@ -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. /// /// - /// When null, defaults to . + /// When null, defaults to . /// public string ViewName { get; set; } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs index d540f14f6f..288c4a76c3 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Infrastructure/DefaultActionSelectorTests.cs @@ -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(), }; diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs index e49e1cb5e4..c63a98b9b0 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ControllerActionDescriptorProviderTests.cs @@ -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(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(), + 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(), + 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(), + 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(), + 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(), + 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()); - action = Assert.Single(actions, a => a.Name == "Create"); + action = Assert.Single(actions, a => a.ActionName == "Create"); Assert.Null(action.GetProperty()); } @@ -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().GroupName); - action = Assert.Single(actions, a => a.Name == "Create"); + action = Assert.Single(actions, a => a.ActionName == "Create"); Assert.Equal("Store", action.GetProperty().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()); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs index 84d5da610c..4e7aed2089 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Routing/KnownRouteValueConstraintTests.cs @@ -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); diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs index 7668613052..a6032ae2a5 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/PartialViewResultExecutorTest.cs @@ -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) diff --git a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs index 4134549e66..e32b246058 100644 --- a/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ViewResultExecutorTest.cs @@ -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) diff --git a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs index f8987b4315..c3f2b4a866 100644 --- a/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.WebApiCompatShimTest/ApiControllerActionDiscoveryTest.cs @@ -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); diff --git a/test/WebSites/ApplicationModelWebSite/Controllers/ActionModelController.cs b/test/WebSites/ApplicationModelWebSite/Controllers/ActionModelController.cs index 7384251025..d68ad4db03 100644 --- a/test/WebSites/ApplicationModelWebSite/Controllers/ActionModelController.cs +++ b/test/WebSites/ApplicationModelWebSite/Controllers/ActionModelController.cs @@ -14,7 +14,7 @@ namespace ApplicationModelWebSite [ActionName2("ActionName")] public string GetActionName() { - return ControllerContext.ActionDescriptor.Name; + return ControllerContext.ActionDescriptor.ActionName; } private class ActionName2Attribute : Attribute, IActionModelConvention diff --git a/test/WebSites/BasicWebSite/Controllers/RoutingController.cs b/test/WebSites/BasicWebSite/Controllers/RoutingController.cs index 34be10972f..c5576b4685 100644 --- a/test/WebSites/BasicWebSite/Controllers/RoutingController.cs +++ b/test/WebSites/BasicWebSite/Controllers/RoutingController.cs @@ -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); } } diff --git a/test/WebSites/FormatterWebSite/ValidateBodyParameterAttribute.cs b/test/WebSites/FormatterWebSite/ValidateBodyParameterAttribute.cs index 8848f815bb..0be7c1fc33 100644 --- a/test/WebSites/FormatterWebSite/ValidateBodyParameterAttribute.cs +++ b/test/WebSites/FormatterWebSite/ValidateBodyParameterAttribute.cs @@ -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" diff --git a/test/WebSites/RoutingWebSite/TestResponseGenerator.cs b/test/WebSites/RoutingWebSite/TestResponseGenerator.cs index d5bad4c7a7..9b85f04456 100644 --- a/test/WebSites/RoutingWebSite/TestResponseGenerator.cs +++ b/test/WebSites/RoutingWebSite/TestResponseGenerator.cs @@ -51,7 +51,7 @@ namespace RoutingWebSite routeName = attributeRoutingInfo == null ? null : attributeRoutingInfo.Name, routeValues = new Dictionary(_actionContext.RouteData.Values), - action = _actionContext.ActionDescriptor.Name, + action = ((ControllerActionDescriptor) _actionContext.ActionDescriptor).ActionName, controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName, link, diff --git a/test/WebSites/VersioningWebSite/TestResponseGenerator.cs b/test/WebSites/VersioningWebSite/TestResponseGenerator.cs index 6b74671f5a..d9ff985c34 100644 --- a/test/WebSites/VersioningWebSite/TestResponseGenerator.cs +++ b/test/WebSites/VersioningWebSite/TestResponseGenerator.cs @@ -49,7 +49,7 @@ namespace VersioningWebSite routeName = attributeRoutingInfo == null ? null : attributeRoutingInfo.Name, routeValues = new Dictionary(_actionContext.RouteData.Values), - action = _actionContext.ActionDescriptor.Name, + action = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ActionName, controller = ((ControllerActionDescriptor)_actionContext.ActionDescriptor).ControllerName, link, diff --git a/test/WebSites/WebApiCompatShimWebSite/ActionSelectionFilter.cs b/test/WebSites/WebApiCompatShimWebSite/ActionSelectionFilter.cs index fb1143fd39..083d9cb643 100644 --- a/test/WebSites/WebApiCompatShimWebSite/ActionSelectionFilter.cs +++ b/test/WebSites/WebApiCompatShimWebSite/ActionSelectionFilter.cs @@ -20,7 +20,7 @@ namespace WebApiCompatShimWebSite { JsonConvert.SerializeObject(new { - ActionName = action.Name, + ActionName = action.ActionName, ControllerName = action.ControllerName }) });