[Fixes #809] Multiple [Http*] verbs should create multiple actions

This commit is contained in:
jacalvar 2014-10-07 18:21:59 -07:00
parent 3f54492930
commit 39376617cc
2 changed files with 62 additions and 30 deletions

View File

@ -170,14 +170,29 @@ namespace Microsoft.AspNet.Mvc
{
var httpMethodProviders = actionAttributes.HttpMethodProviderAttributes;
var httpMethods = httpMethodProviders.SelectMany(x => x.HttpMethods).Distinct().ToArray();
yield return new ActionInfo()
if (httpMethods.Length > 0)
{
HttpMethods = httpMethods,
ActionName = actionName,
Attributes = actionAttributes.Attributes,
RequireActionNameMatch = true,
};
foreach (var httpMethod in httpMethods)
{
yield return new ActionInfo()
{
HttpMethods = new string[] { httpMethod },
ActionName = actionName,
Attributes = actionAttributes.Attributes,
RequireActionNameMatch = true,
};
}
}
else
{
yield return new ActionInfo()
{
HttpMethods = httpMethods,
ActionName = actionName,
Attributes = actionAttributes.Attributes,
RequireActionNameMatch = true,
};
}
}
private static IEnumerable<ActionInfo> GetAttributeRoutedActions(

View File

@ -181,12 +181,17 @@ namespace Microsoft.AspNet.Mvc
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
// Assert
var action = Assert.Single(actionInfos);
Assert.Equal("Update", action.ActionName);
Assert.True(action.RequireActionNameMatch);
Assert.Equal(new[] { "PUT", "PATCH" }, action.HttpMethods);
Assert.Null(action.AttributeRoute);
Assert.IsType<CustomHttpMethodsAttribute>(Assert.Single(action.Attributes));
Assert.Equal(2, actionInfos.Count());
Assert.Single(actionInfos, a => a.HttpMethods.Contains("PUT"));
Assert.Single(actionInfos, a => a.HttpMethods.Contains("PATCH"));
foreach (var action in actionInfos)
{
Assert.Equal("Update", action.ActionName);
Assert.True(action.RequireActionNameMatch);
Assert.Null(action.AttributeRoute);
Assert.IsType<CustomHttpMethodsAttribute>(Assert.Single(action.Attributes));
}
}
[Fact]
@ -224,15 +229,21 @@ namespace Microsoft.AspNet.Mvc
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
// Assert
var action = Assert.Single(actionInfos);
Assert.Equal("Details", action.ActionName);
Assert.True(action.RequireActionNameMatch);
Assert.Equal(new[] { "GET", "POST" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
Assert.Null(action.AttributeRoute);
Assert.Equal(2, actionInfos.Count());
Assert.Single(actionInfos, a => a.HttpMethods.Contains("GET"));
Assert.Single(actionInfos, a => a.HttpMethods.Contains("POST"));
Assert.Equal(2, action.Attributes.Length);
Assert.Single(action.Attributes, a => a is HttpGetAttribute);
Assert.Single(action.Attributes, a => a is HttpPostAttribute);
foreach (var action in actionInfos)
{
Assert.Equal("Details", action.ActionName);
Assert.True(action.RequireActionNameMatch);
Assert.Null(action.AttributeRoute);
Assert.Equal(2, action.Attributes.Length);
Assert.Single(action.Attributes, a => a is HttpGetAttribute);
Assert.Single(action.Attributes, a => a is HttpPostAttribute);
}
}
[Fact]
@ -247,16 +258,22 @@ namespace Microsoft.AspNet.Mvc
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
// Assert
var action = Assert.Single(actionInfos);
Assert.Equal("List", action.ActionName);
Assert.True(action.RequireActionNameMatch);
Assert.Equal(new[] { "GET", "POST", "PUT" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
Assert.Null(action.AttributeRoute);
Assert.Equal(3, actionInfos.Count());
Assert.Single(actionInfos, a => a.HttpMethods.Contains("GET"));
Assert.Single(actionInfos, a => a.HttpMethods.Contains("POST"));
Assert.Single(actionInfos, a => a.HttpMethods.Contains("PUT"));
Assert.Equal(3, action.Attributes.Length);
Assert.Single(action.Attributes, a => a is HttpPutAttribute);
Assert.Single(action.Attributes, a => a is HttpGetAttribute);
Assert.Single(action.Attributes, a => a is AcceptVerbsAttribute);
foreach (var action in actionInfos)
{
Assert.Equal("List", action.ActionName);
Assert.True(action.RequireActionNameMatch);
Assert.Null(action.AttributeRoute);
Assert.Equal(3, action.Attributes.Length);
Assert.Single(action.Attributes, a => a is HttpPutAttribute);
Assert.Single(action.Attributes, a => a is HttpGetAttribute);
Assert.Single(action.Attributes, a => a is AcceptVerbsAttribute);
}
}
[Fact]