Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
[Fixes #4506] Move and rename ActionDescriptor.Name to ControllerActi…
Browse files Browse the repository at this point in the history
…onDescriptor.ActionName
  • Loading branch information
javiercn committed May 26, 2016
1 parent abf9319 commit 6745f22
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public ActionDescriptor()
/// <summary>
/// Gets an id which uniquely identifies the action.
/// </summary>
public string Id { get; }

public virtual string Name { get; set; }
public string Id { get; }

/// <summary>
/// Gets or sets the collection of route values that must be provided by routing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class ControllerActionDescriptor : ActionDescriptor
{
public string ControllerName { get; set; }

public virtual string ActionName { get; set; }

public MethodInfo MethodInfo { get; set; }

public TypeInfo ControllerTypeInfo { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private static ControllerActionDescriptor CreateActionDescriptor(

var actionDescriptor = new ControllerActionDescriptor()
{
Name = action.ActionName,
ActionName = action.ActionName,
MethodInfo = action.ActionMethod,
Parameters = parameterDescriptors,
AttributeRouteInfo = CreateAttributeRouteInfo(actionAttributeRoute, controllerAttributeRoute)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -69,7 +70,7 @@ public virtual ViewEngineResult FindView(ActionContext actionContext, PartialVie
}

var viewEngine = viewResult.ViewEngine ?? ViewEngine;
var viewName = viewResult.ViewName ?? actionContext.ActionDescriptor.Name;
var viewName = viewResult.ViewName ?? (actionContext.ActionDescriptor as ControllerActionDescriptor)?.ActionName;

var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: false);
var originalResult = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -69,7 +70,8 @@ public virtual ViewEngineResult FindView(ActionContext actionContext, ViewResult
}

var viewEngine = viewResult.ViewEngine ?? ViewEngine;
var viewName = viewResult.ViewName ?? actionContext.ActionDescriptor.Name;

var viewName = viewResult.ViewName ?? (actionContext.ActionDescriptor as ControllerActionDescriptor)?.ActionName;

var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
var originalResult = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,7 @@ public class PartialViewResult : ActionResult
/// 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; }

Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,7 @@ public class ViewResult : ActionResult
/// 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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public void HttpMethodAttribute_ActionWithMultipleHttpMethodAttributeViaAcceptVe
var result = InvokeActionSelector(routeContext);

// Assert
Assert.Equal("Patch", result.Name);
Assert.Equal("Patch", result.ActionName);
}

[Theory]
Expand All @@ -419,7 +419,7 @@ public void HttpMethodAttribute_ActionWithMultipleHttpMethodAttributes_ORsMultip
var result = InvokeActionSelector(routeContext);

// Assert
Assert.Equal("Put", result.Name);
Assert.Equal("Put", result.ActionName);
}

[Theory]
Expand Down Expand Up @@ -451,7 +451,7 @@ public void NonActionAttribute_ActionNotReachable(string actionName)
// 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);
Expand Down Expand Up @@ -504,10 +504,10 @@ public void ActionNameAttribute_DifferentActionName_UsesActionNameFromActionName
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();

Expand All @@ -533,7 +533,7 @@ private ActionDescriptor InvokeActionSelector(RouteContext context)
GetActionConstraintCache(actionConstraintProviders),
NullLoggerFactory.Instance);

return defaultActionSelector.Select(context);
return (ControllerActionDescriptor)defaultActionSelector.Select(context);
}

private ControllerActionDescriptorProvider GetActionDescriptorProvider()
Expand Down Expand Up @@ -664,9 +664,9 @@ private static RouteContext CreateRouteContext(string httpMethod)

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>(),
};

Expand Down
Loading

0 comments on commit 6745f22

Please sign in to comment.