|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
| 8 | + using Microsoft.CodeAnalysis.Testing; |
6 | 9 | using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules; |
| 10 | + using Xunit; |
| 11 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 12 | + StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax, |
| 13 | + StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>; |
7 | 14 |
|
8 | 15 | public partial class SA1130CSharp9UnitTests : SA1130CSharp8UnitTests |
9 | 16 | { |
| 17 | + [Fact] |
| 18 | + [WorkItem(3973, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3973")] |
| 19 | + public async Task TestStaticAnonymousMethodAsync() |
| 20 | + { |
| 21 | + var testCode = @"using System; |
| 22 | +
|
| 23 | +public class TestClass |
| 24 | +{ |
| 25 | + public void TestMethod() |
| 26 | + { |
| 27 | + Action a = static {|#0:delegate|} { }; |
| 28 | + } |
| 29 | +} |
| 30 | +"; |
| 31 | + |
| 32 | + var fixedCode = @"using System; |
| 33 | +
|
| 34 | +public class TestClass |
| 35 | +{ |
| 36 | + public void TestMethod() |
| 37 | + { |
| 38 | + Action a = static () => { }; |
| 39 | + } |
| 40 | +} |
| 41 | +"; |
| 42 | + |
| 43 | + await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + [WorkItem(3973, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3973")] |
| 48 | + public async Task TestStaticAnonymousMethodWithParametersAsync() |
| 49 | + { |
| 50 | + var testCode = @"using System; |
| 51 | +
|
| 52 | +public class TestClass |
| 53 | +{ |
| 54 | + public void TestMethod() |
| 55 | + { |
| 56 | + Func<int, int, int> sum = static {|#0:delegate|}(int x, int y) { return x + y; }; |
| 57 | + } |
| 58 | +} |
| 59 | +"; |
| 60 | + |
| 61 | + var fixedCode = @"using System; |
| 62 | +
|
| 63 | +public class TestClass |
| 64 | +{ |
| 65 | + public void TestMethod() |
| 66 | + { |
| 67 | + Func<int, int, int> sum = static (x, y) => { return x + y; }; |
| 68 | + } |
| 69 | +} |
| 70 | +"; |
| 71 | + |
| 72 | + await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 73 | + } |
10 | 74 | } |
11 | 75 | } |
0 commit comments