Skip to content

Commit 77ee36f

Browse files
committed
Added test cases for event initializers
1 parent 67110e8 commit 77ee36f

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/ReadabilityRules/SA1130UnitTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,5 +783,34 @@ public static EventHandler TestProperty1
783783

784784
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
785785
}
786+
787+
[Fact]
788+
[WorkItem(2902, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2902")]
789+
public async Task VerifyThatEventInitializersWorkAsExpectedAsync()
790+
{
791+
var testCode = @"using System;
792+
public class TestClass
793+
{
794+
public static event EventHandler StaticEvent = delegate { };
795+
public event EventHandler InstanceEvent = delegate { };
796+
}
797+
";
798+
799+
var fixedCode = @"using System;
800+
public class TestClass
801+
{
802+
public static event EventHandler StaticEvent = (sender, e) => { };
803+
public event EventHandler InstanceEvent = (sender, e) => { };
804+
}
805+
";
806+
807+
DiagnosticResult[] expected =
808+
{
809+
Diagnostic().WithLocation(4, 52),
810+
Diagnostic().WithLocation(5, 47),
811+
};
812+
813+
await VerifyCSharpFixAsync(testCode, expected, fixedCode, CancellationToken.None).ConfigureAwait(false);
814+
}
786815
}
787816
}

0 commit comments

Comments
 (0)