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

Commit

Permalink
Merge pull request #82 from Chandu/feature-non-action-methods
Browse files Browse the repository at this point in the history
Ignore NonAction actions on controller.
  • Loading branch information
chandu committed Apr 21, 2014
2 parents 6767ce4 + 2f6e453 commit 2a05263
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -30,4 +30,7 @@ _ReSharper*/
[Tt]est[Rr]esult*
NCover*.lic
*.*.dotCover
*.DotSettings
*.DotSettings

#SharpDevelop files
*.sdsettings
30 changes: 30 additions & 0 deletions FluentSecurity.Specification/ConfigurationExpressionSpec.cs
Expand Up @@ -368,6 +368,36 @@ public void Should_have_6_policycontainers()
}
}

[TestFixture]
[Category("ConfigurationExpressionSpec")]
public class When_adding_a_conventionpolicycontainter_for_controller_with_nonaction_actions
{
[Test]
public void Should_not_have_policycontainer_for_actions_marked_as_NonAction()
{
// Arrange
var configurationExpression = new RootConfiguration();
configurationExpression.GetAuthenticationStatusFrom(StaticHelper.IsAuthenticatedReturnsFalse);

// Act
configurationExpression.For<NonActionController>();

// Assert
var policyContainers = configurationExpression.Runtime.PolicyContainers;

Assert.That(configurationExpression.Runtime.PolicyContainers.Count(), Is.EqualTo(0));
}

private class NonActionController : Controller
{
[NonAction]
public ActionResult SomeAction()
{
return null;
}
}
}

[TestFixture]
[Category("ConfigurationExpressionSpec")]
public class When_adding_a_conventionpolicycontainter_for_controller_with_aliased_action
Expand Down
13 changes: 12 additions & 1 deletion FluentSecurity/Extensions.cs
Expand Up @@ -92,7 +92,18 @@ internal static bool IsValidActionMethod(this MethodInfo methodInfo)
return
methodInfo.ReturnType.IsControllerActionReturnType() &&
!methodInfo.IsSpecialName &&
!methodInfo.IsDeclaredBy<Controller>();
!methodInfo.IsDeclaredBy<Controller>() &&
!methodInfo.HasAttribute<NonActionAttribute>();
}

/// <summary>
/// Returns true if the passed method has the attribute of type TAttribute
/// </summary>
/// <param name="methodInfo">MethodInfo of the method to verify</param>
/// <returns></returns>
internal static bool HasAttribute<TAttribute>(this MethodInfo methodInfo) where TAttribute:Attribute
{
return methodInfo.GetCustomAttributes(typeof(TAttribute), false).Any();
}

/// <summary>
Expand Down

0 comments on commit 2a05263

Please sign in to comment.