File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
IDisposableAnalyzers.NetCoreTests/IDISP004DontIgnoreReturnValueOfTypeIDisposableTests
ValidCode.NetCore/AsyncDisposable Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,43 @@ public static class Valid
99 {
1010 private static readonly DiagnosticAnalyzer Analyzer = new CreationAnalyzer ( ) ;
1111
12+ [ Test ]
13+ public static void AwaitUsing ( )
14+ {
15+ var asyncDisposable = @"
16+ namespace N
17+ {
18+ using System;
19+ using System.IO;
20+ using System.Threading.Tasks;
21+
22+ public class AsyncDisposable : IAsyncDisposable
23+ {
24+ private readonly IAsyncDisposable disposable = File.OpenRead(string.Empty);
25+
26+ public async ValueTask DisposeAsync()
27+ {
28+ await this.disposable.DisposeAsync().ConfigureAwait(false);
29+ }
30+ }
31+ }" ;
32+ var code = @"
33+ namespace N
34+ {
35+ using System.Threading.Tasks;
36+
37+ class C
38+ {
39+ public async Task M()
40+ {
41+ await using var asyncDisposable = new AsyncDisposable();
42+ }
43+ }
44+ }
45+ " ;
46+ RoslynAssert . Valid ( Analyzer , asyncDisposable , code ) ;
47+ }
48+
1249 [ Test ]
1350 public static void ILoggerFactoryAddApplicationInsights ( )
1451 {
Original file line number Diff line number Diff line change 1+ namespace ValidCode . NetCore . AsyncDisposable
2+ {
3+ using System . Threading . Tasks ;
4+
5+ class AwaitUsing
6+ {
7+ public async void M1 ( )
8+ {
9+ await using var impl1 = new Impl1 ( ) ;
10+ await using var impl2 = new Impl2 ( ) ;
11+ }
12+
13+ public async Task M2 ( )
14+ {
15+ await using var impl1 = new Impl1 ( ) ;
16+ await using var impl2 = new Impl2 ( ) ;
17+ }
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments