|
1 | 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
2 | 2 | // Licensed under the MIT License. See LICENSE in the project root for license information. |
3 | 3 |
|
4 | | -#nullable disable |
5 | | - |
6 | 4 | namespace StyleCop.Analyzers.Test.CSharp8.LayoutRules |
7 | 5 | { |
8 | 6 | using System.Threading; |
@@ -32,5 +30,69 @@ public void Method() |
32 | 30 |
|
33 | 31 | await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
34 | 32 | } |
| 33 | + |
| 34 | + [Fact] |
| 35 | + [WorkItem(3004, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3004")] |
| 36 | + public async Task TestUsingDeclarationWithFollowingStatementAsync() |
| 37 | + { |
| 38 | + var testCode = @" |
| 39 | +using System.IO; |
| 40 | +public class Foo |
| 41 | +{ |
| 42 | + public int Method() |
| 43 | + { |
| 44 | + using var stream = new MemoryStream(); |
| 45 | + return stream.ReadByte(); |
| 46 | + } |
| 47 | +}"; |
| 48 | + |
| 49 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 50 | + } |
| 51 | + |
| 52 | + [Fact] |
| 53 | + [WorkItem(3004, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3004")] |
| 54 | + public async Task TestAwaitUsingDeclarationStatementAsync() |
| 55 | + { |
| 56 | + var testCode = @" |
| 57 | +using System; |
| 58 | +using System.Threading.Tasks; |
| 59 | +
|
| 60 | +public class Foo |
| 61 | +{ |
| 62 | + public async Task MethodAsync() |
| 63 | + { |
| 64 | + await using var resource = new AsyncDisposable(); |
| 65 | + await Task.Yield(); |
| 66 | + } |
| 67 | +
|
| 68 | + private sealed class AsyncDisposable : IAsyncDisposable |
| 69 | + { |
| 70 | + public ValueTask DisposeAsync() |
| 71 | + { |
| 72 | + return default; |
| 73 | + } |
| 74 | + } |
| 75 | +}"; |
| 76 | + |
| 77 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 78 | + } |
| 79 | + |
| 80 | + [Fact] |
| 81 | + [WorkItem(3004, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3004")] |
| 82 | + public async Task TestMultipleUsingDeclarationsAsync() |
| 83 | + { |
| 84 | + var testCode = @" |
| 85 | +using System.IO; |
| 86 | +public class Foo |
| 87 | +{ |
| 88 | + public void Method() |
| 89 | + { |
| 90 | + using MemoryStream stream1 = new MemoryStream(), stream2 = new MemoryStream(); |
| 91 | + _ = stream1.ReadByte() + stream2.ReadByte(); |
| 92 | + } |
| 93 | +}"; |
| 94 | + |
| 95 | + await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 96 | + } |
35 | 97 | } |
36 | 98 | } |
0 commit comments