|
3 | 3 |
|
4 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.ReadabilityRules |
5 | 5 | { |
| 6 | + using System.Threading; |
| 7 | + using System.Threading.Tasks; |
6 | 8 | using StyleCop.Analyzers.Test.CSharp7.ReadabilityRules; |
| 9 | + using Xunit; |
| 10 | + using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier< |
| 11 | + StyleCop.Analyzers.ReadabilityRules.SA1130UseLambdaSyntax, |
| 12 | + StyleCop.Analyzers.ReadabilityRules.SA1130CodeFixProvider>; |
7 | 13 |
|
8 | 14 | public partial class SA1130CSharp8UnitTests : SA1130CSharp7UnitTests |
9 | 15 | { |
| 16 | + [Fact] |
| 17 | + [WorkItem(3006, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006")] |
| 18 | + public async Task TestDelegateInNullableEnabledGenericAsync() |
| 19 | + { |
| 20 | + var testCode = @"#nullable enable |
| 21 | +using System; |
| 22 | +
|
| 23 | +public class TestClass |
| 24 | +{ |
| 25 | + public void TestMethod<T>() where T : class |
| 26 | + { |
| 27 | + Func<T?> resolve = {|#0:delegate|} { return default; }; |
| 28 | + } |
| 29 | +} |
| 30 | +"; |
| 31 | + |
| 32 | + var fixedCode = @"#nullable enable |
| 33 | +using System; |
| 34 | +
|
| 35 | +public class TestClass |
| 36 | +{ |
| 37 | + public void TestMethod<T>() where T : class |
| 38 | + { |
| 39 | + Func<T?> resolve = () => { return default; }; |
| 40 | + } |
| 41 | +} |
| 42 | +"; |
| 43 | + |
| 44 | + await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + [WorkItem(3006, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3006")] |
| 49 | + public async Task TestDelegateUsedAsNamedArgumentWithNullableTypesAsync() |
| 50 | + { |
| 51 | + var testCode = @"#nullable enable |
| 52 | +using System; |
| 53 | +using System.Linq; |
| 54 | +
|
| 55 | +public class TestClass |
| 56 | +{ |
| 57 | + public void Test() |
| 58 | + { |
| 59 | + Invoke(resolve: {|#0:delegate|} |
| 60 | + { |
| 61 | + return """"; |
| 62 | + }); |
| 63 | + } |
| 64 | +
|
| 65 | + private void Invoke(string? description = null, Func<object?, string?> resolve = null!) |
| 66 | + { |
| 67 | + _ = resolve(0); |
| 68 | + } |
| 69 | +} |
| 70 | +"; |
| 71 | + |
| 72 | + var fixedCode = @"#nullable enable |
| 73 | +using System; |
| 74 | +using System.Linq; |
| 75 | +
|
| 76 | +public class TestClass |
| 77 | +{ |
| 78 | + public void Test() |
| 79 | + { |
| 80 | + Invoke(resolve: arg => |
| 81 | + { |
| 82 | + return """"; |
| 83 | + }); |
| 84 | + } |
| 85 | +
|
| 86 | + private void Invoke(string? description = null, Func<object?, string?> resolve = null!) |
| 87 | + { |
| 88 | + _ = resolve(0); |
| 89 | + } |
| 90 | +} |
| 91 | +"; |
| 92 | + |
| 93 | + await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false); |
| 94 | + } |
10 | 95 | } |
11 | 96 | } |
0 commit comments