parent
fdbac041f9
commit
e27742fd0b
|
|
@ -79,10 +79,16 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return String.Equals(methodInfo.Name, DefaultMethodName, StringComparison.OrdinalIgnoreCase);
|
return String.Equals(methodInfo.Name, DefaultMethodName, StringComparison.OrdinalIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the method is a valid action.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="method">The <see cref="MethodInfo"/>.</param>
|
||||||
|
/// <returns>true if the method is a valid action. Otherwise, false.</returns>
|
||||||
protected virtual bool IsValidActionMethod(MethodInfo method)
|
protected virtual bool IsValidActionMethod(MethodInfo method)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
method.IsPublic &&
|
method.IsPublic &&
|
||||||
|
!method.IsStatic &&
|
||||||
!method.IsAbstract &&
|
!method.IsAbstract &&
|
||||||
!method.IsConstructor &&
|
!method.IsConstructor &&
|
||||||
!method.IsGenericMethod &&
|
!method.IsGenericMethod &&
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionNames = GetDescriptors(typeof(BaseController).GetTypeInfo()).Select(a => a.Name);
|
var actionNames = GetDescriptors(typeof(BaseController).GetTypeInfo()).Select(a => a.Name);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(actionNames.Contains("Redirect"));
|
Assert.DoesNotContain("Redirect", actionNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionNames = GetActionNamesFromDerivedController();
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(actionNames.Contains("PrivateMethod"));
|
Assert.DoesNotContain("PrivateMethod", actionNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionNames = GetActionNamesFromDerivedController();
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(actionNames.Contains("DerivedController"));
|
Assert.DoesNotContain("DerivedController", actionNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionNames = GetActionNamesFromDerivedController();
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(actionNames.Contains("GenericMethod"));
|
Assert.DoesNotContain("GenericMethod", actionNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -84,7 +84,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
var actionNames = GetActionNamesFromDerivedController();
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.False(actionNames.Contains("OverridenNonActionMethod"));
|
Assert.DoesNotContain("OverridenNonActionMethod", actionNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -100,6 +100,36 @@ namespace Microsoft.AspNet.Mvc
|
||||||
Assert.Empty(methodsFromObjectClass.Intersect(actionNames));
|
Assert.Empty(methodsFromObjectClass.Intersect(actionNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDescriptors_Ignores_StaticMethod_FromUserDefinedController()
|
||||||
|
{
|
||||||
|
// Arrange & Act
|
||||||
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.DoesNotContain("StaticMethod", actionNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDescriptors_Ignores_ProtectedStaticMethod_FromUserDefinedController()
|
||||||
|
{
|
||||||
|
// Arrange & Act
|
||||||
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.DoesNotContain("ProtectedStaticMethod", actionNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetDescriptors_Ignores_PrivateStaticMethod_FromUserDefinedController()
|
||||||
|
{
|
||||||
|
// Arrange & Act
|
||||||
|
var actionNames = GetActionNamesFromDerivedController();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.DoesNotContain("PrivateStaticMethod", actionNames);
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<string> GetActionNamesFromDerivedController()
|
private IEnumerable<string> GetActionNamesFromDerivedController()
|
||||||
{
|
{
|
||||||
return GetDescriptors(typeof(DerivedController).GetTypeInfo()).Select(a => a.Name);
|
return GetDescriptors(typeof(DerivedController).GetTypeInfo()).Select(a => a.Name);
|
||||||
|
|
@ -143,6 +173,18 @@ namespace Microsoft.AspNet.Mvc
|
||||||
private void PrivateMethod()
|
private void PrivateMethod()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void StaticMethod()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void ProtectedStaticMethod()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PrivateStaticMethod()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class OperatorOverloadingController : Controller
|
private class OperatorOverloadingController : Controller
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue