Skip to content

Commit

Permalink
- demonstrates an issue where anonymous delegates nested inside a met…
Browse files Browse the repository at this point in the history
…hod do not correctly have the parent methods SuppressMessage attributes applied
  • Loading branch information
Iristyle committed Apr 24, 2011
1 parent 5795813 commit 47eb3f6
Showing 1 changed file with 31 additions and 1 deletion.
Expand Up @@ -33,6 +33,8 @@
using NUnit.Framework;
using Test.Rules.Definitions;
using Test.Rules.Fixtures;
using System.Diagnostics.CodeAnalysis;
using Test.Rules.Helpers;

namespace Test.Rules.BadPractice {

Expand Down Expand Up @@ -183,5 +185,33 @@ public void Good ()
AssertRuleSuccess<BadTryParse> ("CallParse");
}
}
}

[TestFixture]
public class PreferTryParseWithSuppressionsTest : MethodRuleTestFixture<PreferTryParseRule>
{
public static class DelegateHolder
{
public static Func<DateTime> Now = () => DateTime.Now;
}
public class SuppressionTest
{
public void ParseDateInDelegate()
{
DelegateHolder.Now = () => DateTime.Parse("4/6/2011 9:38:12 PM", CultureInfo.CurrentCulture);
}
}

[Test]
public void ProperlySuppresses()
{
Runner.IgnoreList.Add("Gendarme.Rules.BadPractice.PreferTryParseRule", DefinitionLoader.GetMethodDefinition<SuppressionTest>("ParseDateInDelegate"));
foreach (var method in DefinitionLoader.GetTypeDefinition<SuppressionTest>().Methods)
{
//the delegate in ParseDataInDelegate (which shows up as another method on the given type) should pick up the rule applied above, but doesn't
if (!method.IsConstructor)
AssertRuleDoesNotApply(method);
}

}
}
}

0 comments on commit 47eb3f6

Please sign in to comment.