[Fixes #809] Multiple [Http*] verbs should create multiple actions
This commit is contained in:
parent
3f54492930
commit
39376617cc
|
|
@ -170,14 +170,29 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
var httpMethodProviders = actionAttributes.HttpMethodProviderAttributes;
|
var httpMethodProviders = actionAttributes.HttpMethodProviderAttributes;
|
||||||
var httpMethods = httpMethodProviders.SelectMany(x => x.HttpMethods).Distinct().ToArray();
|
var httpMethods = httpMethodProviders.SelectMany(x => x.HttpMethods).Distinct().ToArray();
|
||||||
|
if (httpMethods.Length > 0)
|
||||||
yield return new ActionInfo()
|
|
||||||
{
|
{
|
||||||
HttpMethods = httpMethods,
|
foreach (var httpMethod in httpMethods)
|
||||||
ActionName = actionName,
|
{
|
||||||
Attributes = actionAttributes.Attributes,
|
yield return new ActionInfo()
|
||||||
RequireActionNameMatch = true,
|
{
|
||||||
};
|
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(
|
private static IEnumerable<ActionInfo> GetAttributeRoutedActions(
|
||||||
|
|
|
||||||
|
|
@ -181,12 +181,17 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
|
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var action = Assert.Single(actionInfos);
|
Assert.Equal(2, actionInfos.Count());
|
||||||
Assert.Equal("Update", action.ActionName);
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("PUT"));
|
||||||
Assert.True(action.RequireActionNameMatch);
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("PATCH"));
|
||||||
Assert.Equal(new[] { "PUT", "PATCH" }, action.HttpMethods);
|
|
||||||
Assert.Null(action.AttributeRoute);
|
foreach (var action in actionInfos)
|
||||||
Assert.IsType<CustomHttpMethodsAttribute>(Assert.Single(action.Attributes));
|
{
|
||||||
|
Assert.Equal("Update", action.ActionName);
|
||||||
|
Assert.True(action.RequireActionNameMatch);
|
||||||
|
Assert.Null(action.AttributeRoute);
|
||||||
|
Assert.IsType<CustomHttpMethodsAttribute>(Assert.Single(action.Attributes));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -224,15 +229,21 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
|
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var action = Assert.Single(actionInfos);
|
Assert.Equal(2, actionInfos.Count());
|
||||||
Assert.Equal("Details", action.ActionName);
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("GET"));
|
||||||
Assert.True(action.RequireActionNameMatch);
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("POST"));
|
||||||
Assert.Equal(new[] { "GET", "POST" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
|
|
||||||
Assert.Null(action.AttributeRoute);
|
|
||||||
|
|
||||||
Assert.Equal(2, action.Attributes.Length);
|
foreach (var action in actionInfos)
|
||||||
Assert.Single(action.Attributes, a => a is HttpGetAttribute);
|
{
|
||||||
Assert.Single(action.Attributes, a => a is HttpPostAttribute);
|
|
||||||
|
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]
|
[Fact]
|
||||||
|
|
@ -247,16 +258,22 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
|
var actionInfos = conventions.GetActions(typeInfo.GetMethod(actionName), typeInfo);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var action = Assert.Single(actionInfos);
|
Assert.Equal(3, actionInfos.Count());
|
||||||
Assert.Equal("List", action.ActionName);
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("GET"));
|
||||||
Assert.True(action.RequireActionNameMatch);
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("POST"));
|
||||||
Assert.Equal(new[] { "GET", "POST", "PUT" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
|
Assert.Single(actionInfos, a => a.HttpMethods.Contains("PUT"));
|
||||||
Assert.Null(action.AttributeRoute);
|
|
||||||
|
|
||||||
Assert.Equal(3, action.Attributes.Length);
|
foreach (var action in actionInfos)
|
||||||
Assert.Single(action.Attributes, a => a is HttpPutAttribute);
|
{
|
||||||
Assert.Single(action.Attributes, a => a is HttpGetAttribute);
|
Assert.Equal("List", action.ActionName);
|
||||||
Assert.Single(action.Attributes, a => a is AcceptVerbsAttribute);
|
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]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue