Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: We should not have NonAction methods show up in the mapping table [760]

$
0
0
Today, if I have a public class like the following, the GetEntityByKey will show up in the mappings.

[Theory]
[InlineData("GetKey", "GET")]
[InlineData("GetEntityByKey", "GET")]
[InlineData("CreateEntity", "PUT")]
[InlineData("UpdateEntity", "POST")]
[InlineData("PatchEntity", "PATCH")]
public void NonActionMethods_CannotBeSelected_InActionSelector(string nonActionMethod, string httpVerb)
{
// Arrange
HttpConfiguration config = new HttpConfiguration();
IHttpActionSelector actionSelector = config.Services.GetActionSelector();
HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(httpVerb), "http://localhost/FormatterPeople");
HttpRouteData routeData = new HttpRouteData(new HttpRoute());
routeData.Values.Add("key", "someKey");
request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
HttpControllerDescriptor controllerDescriptor = new HttpControllerDescriptor(config, "Employees", typeof(EmployeesController));
HttpControllerContext controllerContext = new HttpControllerContext(config, routeData, request)
{
ControllerDescriptor = controllerDescriptor
};

// Act & Assert
ILookup<string, HttpActionDescriptor> actionMappings = actionSelector.GetActionMapping(controllerDescriptor);
Assert.True(actionMappings.Contains(nonActionMethod)); // this should be false.

public class EmployeesController : ApiController
{
[NonAction]
public EmployeesController.Employee GetEntityByKey(Guid key)
{
return new EmployeesController.Employee() { EmployeeID = key, EmployeeName = "Bob" };
}

public class Employee
{
public Guid EmployeeID { get; set; }
public string EmployeeName { get; set; }
}
}
Comments: Yes, fixed it not. We should NOT have NonAction methods show up in the mapping tables.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>